alonity/cache

Alonity 缓存

dev-main 2022-08-27 15:16 UTC

This package is auto-updated.

Last update: 2024-09-27 20:22:59 UTC


README

缓存组件

安装

composer require alonity/cache

示例

use alonity\cache\Cache;

require('vendor/autoload.php');

require_once('../vendor/autoload.php');

/**
 * Set storage
 * Default value: file
 * Supported storages: file, mongodb, redis, memcached, memcache
*/
Cache::$config['storage'] = 'mongodb';

// Set save path for file storage 
Cache::$config['path'] = __DIR__.'/tmp/cache';

$storage = Cache::getStorage();

// Check storage if defined
if(is_null($storage)){
    exit(Cache::$error);
}

if(!Cache::save('hello', [
    ['id' => 1, 'name' => 'test'],
    ['id' => 2, 'name' => 'test2']
])){
    exit(Cache::$error);
}

var_dump(Cache::get('hello'));

文档: https://alonity.gitbook.io/alonity/components/cache