php cache
5.1.0
Implementasi PSR/Cache Sederhana untuk PHP 8.1+.
Anda dapat mengkloning repo dan menjalankan composer install di direktori root. Jika Anda ingin memasukkannya ke tempat lain, cukup tambahkan yang berikut ini ke komposer Anda.
(Catatan: Ganti dev-main dengan kendala versi, misalnya ^4.1 - lihat rilis untuk versi yang valid)
{
"require" : {
"php" : " ^8.1 " ,
"chillerlan/php-cache" : " dev-main "
}
} Instalasi melalui Terminal: composer require chillerlan/php-cache
Laba!
Cukup memohon contoh cache dengan CacheInterface yang diinginkan seperti itu:
// 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 ; Lihat: 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 ):boolSaya tidak bertanggung jawab atas modul memori cair, hard disk kembung, DOS yang diinduksi sendiri, layar rusak dll. Gunakan dengan risiko Anda sendiri! ?