akeb / cache
v1.1.7
2024-05-22 09:08 UTC
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: @stable
README
安装
composer 项目 akeb/cache
Composer 配置
{ "require": { "akeb/cache": "^1.1.6" }, "repositories": [ { "type": "vcs", "url": "https://github.com/AKEB/Framework-AKEB-cache" } ] }
或
composer require akeb/cache
如果你使用 memcached
global $CACHE_SERVERS; $CACHE_SERVERS = [ 'default' => ['host'=>'localhost', 'port' => 11211] ]; require_once("../vendor/autoload.php");
如果你使用 FileCache
define('USE_FILE_CACHE', true); // Forcing the use of the file cache define('PATH_CACHE', '/opt/www/cache/'); // Cache file directory require_once("../vendor/autoload.php");
示例使用 Cache
Memcached 缓存
global $CACHE_SERVERS; $CACHE_SERVERS = [ 'default' => ['host'=>'localhost', 'port' => 11211], // Description memcached servers ]; require_once("../vendor/autoload.php"); $dateString = ''; $cache = new \Cache('testDate','default'); // Init Cache Object with name "testDate" if (!$cache->isValid() && $cache->tryLock()) { // If cache not valid and we can lock cache // Do something $dateString = date("Y-m-d H:i:s", time()); $cache->update($dateString,600); // Update cache data $cache->freeLock(); // Free lock } else { // Cache valid, or we can't lock cache $dateString = $cache->get(); // get data from cache } echo $dateString.PHP_EOL;
文件缓存
define('PATH_CACHE', './tmp/'); // Cache file directory require_once("../vendor/autoload.php"); $dateString = ''; $cache = new \Cache('testDate','default'); // Init Cache Object with name "testDate" if (!$cache->isValid() && $cache->tryLock()) { // If cache not valid and we can lock cache // Do something $dateString = date("Y-m-d H:i:s", time()); $cache->update($dateString,600); // Update cache data $cache->freeLock(); // Free lock } else { // Cache valid, or we can't lock cache $dateString = $cache->get(); // get data from cache } echo $dateString.PHP_EOL;
更多详细信息,请参阅 examples
文件夹。
运行单元测试
./dockerTest.sh