gueff/cachix

一个简单的PHP文件缓存类

1.0.2 2023-04-22 13:41 UTC

This package is auto-updated.

Last update: 2024-09-22 17:22:03 UTC


README

一个简单的PHP文件缓存类

要求

  • PHP >= 7.4
  • Linux 命令 rmfindgrep 必须通过 PHP 的 shell_exec 命令可执行

安装

创建 composer.json 文件,内容如下

{
    "require": {
        "gueff/cachix":"1.0.2"
    }
}

运行安装

$ composer install

用法

<?php

// init Config
\Cachix::init(array(
    'bCaching' => true,
	'sCacheDir' => '/tmp/',
	'iDeleteAfterMinutes' => 10,
	'sBinRemove' => '/bin/rm',
	'sBinFind' => '/usr/bin/find',
	'sBinGrep' => '/bin/grep'
));

// build a Cache-Key
$sKey = 'myCacheKey.Token';

// autodelete cachefiles
// which contain the string ".Token" in key-names
\Cachix::autoDeleteCache('.Token');

// first time saving data to cache...
if (empty(\Cachix::getCache($sKey)))
{
    // Data to be cached
    $aData = ['foo' => 'bar'];
    
    \Cachix::saveCache(
       	$sKey,
     	$aData
    );
}
// ...or read from existing Cache
else
{
    $aData = \Cachix::getCache($sKey);
}