php cache
5.1.0
PHP 8.1+のPSR/シンプルキャッシュ実装。
ルートディレクトリでリポジトリをクローンし、 composer installを実行するだけです。他の場所に含めたい場合は、 composer.jsonに次のことを追加してください。
(注: dev-mainバージョンの制約に置き換えます。たとえば^4.1有効なバージョンのリリースを参照してください)
{
"require" : {
"php" : " ^8.1 " ,
"chillerlan/php-cache" : " dev-main "
}
}ターミナル経由のインストール: composer require chillerlan/php-cache
利益!
SOのような目的のCacheInterfaceを使用して、キャッシュインスタンスを呼び出すだけです。
// Redis
$ redis = new Redis ;
$ redis -> pconnect ( ' 127.0.0.1 ' , 6379 );
$ cache = new RedisCache ( $ redis );
// Memcached
$ memcached = new Memcached ( ' myCacheInstance ' );
$ memcached -> addServer ( ' localhost ' , 11211 );
$ cache = new MemcachedCache ( $ memcached );
// APCU
$ cache = new APCUCache ;
// File
$ cache = new FileCache ( new CacheOptions ([ ' cacheFilestorage ' => __DIR__ . ' /../.cache ' ]));
// Session
$ cache = new SessionCache ( new CacheOptions ([ ' cacheSessionkey ' => ' _my_session_cache ' ]));
// Memory
$ cache = new MemoryCache ;参照: PsrSimpleCacheCacheInterface
$ cache -> get (string $ key , $ default = null ); // -> mixed
$ cache -> set (string $ key , $ value , int $ ttl = null ):bool
$ cache -> delete (string $ key ):bool
$ cache -> has (string $ key ):bool
$ cache ->clear():bool
$ cache -> getMultiple (array $ keys , $ default = null ):array // -> mixed[]
$ cache -> setMultiple (array $ values , int $ ttl = null ):bool
$ cache -> deleteMultiple (array $ keys ):bool私は、溶融メモリモジュール、肥大化したハードディスク、自己誘発DOS、壊れたスクリーンなどに責任を負いません。あなた自身の責任で使用してください! ?