php cache
5.1.0
การใช้งาน PSR/Simple-Cache สำหรับ PHP 8.1+
คุณสามารถโคลน repo และเรียกใช้ composer install ในไดเรกทอรีรูท ในกรณีที่คุณต้องการรวมไว้ที่อื่นเพียงเพิ่มสิ่งต่อไปนี้ลงใน นักแต่งเพลง ของคุณ json:
(หมายเหตุ: แทนที่ dev-main ด้วยข้อ จำกัด ของเวอร์ชันเช่น ^4.1 - ดูรุ่นสำหรับรุ่นที่ถูกต้อง)
{
"require" : {
"php" : " ^8.1 " ,
"chillerlan/php-cache" : " dev-main "
}
} การติดตั้งผ่านเทอร์มินัล: composer require chillerlan/php-cache
กำไร!
เพียงเรียกใช้อินสแตนซ์แคชที่มี CacheInterface ที่ต้องการเช่น So:
// 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 ที่เหนี่ยวนำด้วยตนเอง, หน้าจอที่หัก ฯลฯ ใช้ความเสี่ยงของคุณเอง! -