jaredchu/simple-cache

基于临时文件的简单PHP对象缓存

v1.1.1 2017-10-11 09:39 UTC

This package is not auto-updated.

Last update: 2024-09-29 04:31:18 UTC


README

基于临时文件的简单PHP对象缓存

Packagist Packagist Travis Scrutinizer Codecov Packagist FOSSA Status

安装

$ composer require jaredchu/simple-cache

使用

快速开始

use JC\Cache\SimpleCache;

// store your object
SimpleCache::add('your-key', new Person('Jared', 27));

// check if exists
SimpleCache::exists('your-key');

// fetch your object
$person = SimpleCache::fetch('your-key', Person::class);

// remove your cache
SimpleCache::remove('your-key');

添加

// cache object Person with lifetime 1000 seconds (default is 0, not expire)
SimpleCache::add('your-key', new Person('Jared', 27), 1000);

获取

if(SimpleCache::exists('your-key')){
  $person = SimpleCache::fetch('your-key', Person::class);
  $person->sayHi();
}

移除

SimpleCache::remove('your-key');

安全

// your data is already encrypt but you can set your own encrypt key
SimpleCache::setEncryptKey('your unique string');
SimpleCache::add('your-key', new Person('Jared', 27));

// you must set encrypt key again if you want to call fetch in another session
SimpleCache::setEncryptKey('your unique string');
$person = SimpleCache::fetch('your-key', Person::class);

贡献

  1. 分支它!
  2. 创建你的功能分支: $ git checkout -b feature/your-new-feature
  3. 提交你的更改: $ git commit -am '添加一些功能'
  4. 推送到分支: $ git push origin feature/your-new-feature
  5. 提交拉取请求。

许可证

MIT许可证

FOSSA Status