承接 simplesoftwareio/simple-cache 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

simplesoftwareio/simple-cache

Composer 安装命令:

composer require simplesoftwareio/simple-cache

包简介

An easy to use caching trait for Laravel's Eloquent Models.

README 文档

README

Build Status Latest Stable Version Latest Unstable Version License Total Downloads

Try our dead simple, free file transfer service keep.sh

Configuration

Composer

First, add the Simple Cache package to your require in your composer.json file:

"require": {
	"simplesoftwareio/simple-cache": "~1"
}

Next, run the composer update command.

Usage

The cacheable trait may be used by adding the trait to the Eloquent model of your choice.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use SimpleSoftwareIO\Cache\Cacheable;

class User extends Model
{
    use Cacheable;
}

Yes, it really is that simple to use. The settings will use the default Cache store set up in your Laravel application. Further, models will be cached for 30 minutes by default.

Properties

cacheLength

You may adjust the default cache length by modifying the cacheLength property on the model.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use SimpleSoftwareIO\Cache\Cacheable;

class User extends Model
{
    use Cacheable;
    protected $cacheLength = 60; //Will cache for 60 minutes
}

cacheStore

The configured cache store may also be adjusted by modifying the cacheStore property. The cache store will need to be set up in your application's config/cache.php configuration file.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use SimpleSoftwareIO\Cache\Cacheable;

class User extends Model
{
    use Cacheable;
    protected $cacheStore = 'redis'; //Will use the configured `redis` store set up in your `config/cache.php` file.
}

cacheBusting

Cache busting will automatically invalid the cache when an insert/update/delete command is ran by your models. You can enable this feature by setting the cacheBusting property to true on your Eloquent model. By default this feature is disabled.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use SimpleSoftwareIO\Cache\Cacheable;

class User extends Model
{
    use Cacheable;
    protected $cacheBusting = true;

}

Be careful! Eloquent Model's with a high amount of insert/update/delete traffic should not use the cache busting feature. The large amount of changes will invalid the model too often and cause the cache to be useless. It is better to set a lower cache length to invalid the results frequently if up to date data is required.

Methods

flush()

The flush method will flush the cache for a model.

(new User)->flush()  //Cache is flushed for the `User` model.

isBusting()

isBusting will return the current status of the cacheBusting property.

if((new User)->isBusting()) {
    // Is cache busting
}

remember($length)

remember will set the length of time in minutes to remember an Eloquent query.

User::remember(45)->where('id', 4')->get();

rememberForever()

rememberForever will remember a query forever. Well, technically 10 years but lets pretend it is forever eh?

User::rememberForever()->where('id', 4')->get();

dontRemember()

And lastly, dontRemember will not cache a query result.

User::dontRemember(0)->where('id', 4')->get();

统计信息

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

GitHub 信息

  • Stars: 23
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-12-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固