mactronique/phpcache

此包已被放弃,不再维护。作者建议使用psr/simple-cache包代替。

PHP高级缓存管理器。驱动:xcache和wincache

1.0.5 2016-11-09 20:05 UTC

This package is auto-updated.

Last update: 2022-02-01 12:49:39 UTC


README

Build Status Dependency Status Latest Stable Version Latest Unstable Version License

支持的驱动

  • xCache
  • WinCache
  • Predis
  • Redis
  • Memcached
  • 空(用于实例化无效果的缓存驱动器)

安装

php composer.phar require mactronique/phpcache "~1.0"

配置

针对 xCache

无需配置。

针对 WinCache

无需配置。

针对 Null

无需配置。

针对 Predis

$config = array(
	"host" => "127.0.0.1",
	"port" => "",
	"password" => "",
	"database" => "",
	"timeout" => 1,
	"read_write_timeout" => 1
);

只需要 host 键。

针对 Redis

$config = array(
	"host" => "127.0.0.1",
	"port" => "",
	"password" => "",
	"database" => "",
	"timeout" => 1
);

只需要 host 键。

针对 Redis

$config = array(
	"host" => "127.0.0.1",
	"port" => 11211,
	"sharing" => 100
);

只需要 host 键。

NullDriver 使用示例

此代码是服务类示例

use Mactronique\PhpCache\Service\PhpCache;
use Mactronique\PhpCache\Driver\NullDriver;

class myService
{
	private $cache
	public function __construct(PhpCache $cache = null)
	{
		if (null === $cache) {
			$cache = new PhpCache();
			$cache->registerDriver(new NullDriver());
		}
		$this->cache = $cache;
	}

	public function myAction()
	{
		/*
		You can use the cache but never key exist and all get return null.
		*/
		$val = $this->cache->get('key');
		[...]
	}
}