定制 silassiai/laravel-table-cache 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

silassiai/laravel-table-cache

Composer 安装命令:

composer require silassiai/laravel-table-cache

包简介

Solution to easily cache tables records, the package uses the laravel Cache facade.

README 文档

README

If you are working with a lot of data, it may not be best practice to work with collections (who are cached by laravel).

Instead of using (which returns a collection):

// for example in a cronjob that caches the users table
$users = cache()->rememberForever('users', function () {
    return DB::table('users')->pluck('email', 'id');
});
// when you need to check if this user exists somewhere later in your application
$users->where('email', 'john@do.nl')->exists();

We could do (which caches all the key values from the model directly in the cache):

// for example in a cronjob that caches the users table
User::cacheColumnKey('email')->withColumnValue('id');
// when you need to check if this user exists somewhere later in your application
User::cacheColumnKey('email')->isCached('john@do.nl');
// or if you need the value
User::cacheColumnKey('email')->getKeyValue('john@do.nl'); // returns the id in this case

Solution to easily cache tables records, the package uses the laravel Cache facade.

Installation

You can install the package via composer:

composer require silassiai/laravel-table-cache

Basic usage

Trait Key Value

You can add the TableCacheKeyValueTrait to you model to easily cache key value pairs (two columns) for your whole table. This can be handy when you want to cache the whole table after you seeded the model.

<?php

namespace App\Models;

use Silassiai\LaravelTableCache\Traits\TableCacheKeyValueTrait;

class BlackList
{
    use TableCacheKeyValueTrait;
}

next add to your seeder:

    public function run()
    {
        // Your seed code here...
        
        BlackList::cacheColumnKey('name')->withColumnValue('your_column_name');
    }

You can also use a default value:

    public function run()
    {
        // Your seed code here...
        
        BlackList::cacheColumnKey('name')->withDefaultValue(true);
    }

To check if the value has been cached

BlackList::cacheColumnKey('name')->isCached('suspicious.com')

To get the cached value

BlackList::cacheColumnKey('name')->getKeyValue('suspicious.com')

To check if the table column is already cached:

BlackList::hasTableKeyCached('name')

统计信息

  • 总下载量: 2.7k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固