2017 © Pedro Peláez
 

library smart-cache

Modify the cache refresh time as the number of requests changes

image

smart-cache/smart-cache

Modify the cache refresh time as the number of requests changes

  • Saturday, November 18, 2017
  • by zhanjinbiao
  • Repository
  • 1 Watchers
  • 0 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

smart-cache

Modify the cache refresh time as the number of requests changes, (*1)

使用方式
  • 引入smartCache.php文件
require __DIR__.'/vendor/smart-cache/smart-cache/src/SmartCache.php';
  • 配置文件 /smart-cache/src/config.php

default属性表示缓存方式,暂时只有redis, (*2)

redis[default] 使用的时候默认的配置,可以添加任意组的配置然后使用,配置格式:, (*3)

'default' => [
    'host'     => 'localhost',
    'password' => null,
    'port'     => 6379,
    'database' => 0,
],
'addTest' => [
    'host'     => 'localhost',
    'password' => null,
    'port'     => 6379,
    'database' => 1,
]
  • 调用实例
$a = 10;
$smartCache = new SmartCache();

//更换为addTest的配置
$smartCache->connection('addTest');
/**保存缓存
*第一个参数为保存的键,
*第二个为保存的值可以是字符串或者数组,
*第三个参数为保存的时长,
*/
$res = $smartCache->saveCache('test',['name'=>'czhan','level'=>999],10);

//获取缓存,只需传入键值
$data = $smartCache->getCache('test');

//清楚缓存
$data = $smartCache->deleteCache('test')

//以数组形式传入配置,第一个参数为host,
//第二个参数为part(默认为6379),第三参数为密码(没有则为null,或者不传)
//第四个参数为选择的database可以不传
$smartCache->connection(['127.0.0.1','6379',null,0]);

$smartCache->connection(['127.0.0.1','6379','test']);

$smartCache->connection(['127.0.0.1','6379']);

$smartCache->connection(['127.0.0.1']);

并且支持redis对象原本的所有方法,keys等操作。, (*4)

The Versions

18/11 2017

dev-master

9999999-dev

Modify the cache refresh time as the number of requests changes

  Sources   Download

The Requires

  • php >=5.6.0

 

by Avatar zhanjinbiao

cache php

08/11 2017

1.0.1

1.0.1.0

Modify the cache refresh time as the number of requests changes

  Sources   Download

The Requires

  • php >=5.6.0

 

by Avatar zhanjinbiao

cache php