00f100 / fcphp-cache
此软件包最新版本(0.3.3)没有可用的许可证信息。
FcPhp 缓存索引
0.3.3
2018-08-04 22:56 UTC
Requires
- php: >=7.2
- ext-redis: *
- 00f100/fcphp-crypto: 0.*
- 00f100/fcphp-redis: 0.*
Requires (Dev)
- 00f100/phpdbug: *
- phpunit/phpunit: 6.*
This package is not auto-updated.
Last update: 2024-09-24 23:06:42 UTC
README
用于管理缓存索引和加密内容的软件包,使用 Sodium PHP (可选)
如何安装
Composer
$ composer require 00f100/fcphp-cache
或添加到 composer.json 中
{ "require": { "00f100/fcphp-cache": "*" } }
如何使用
<?php use FcPhp\Cache\Facades\CacheFacade; use FcPhp\Crypto\Crypto; /** * Method to create new instance of Cache * * @param string|array $cacheRepository Configuration of redis or path to save files cache * @param string $nonce Nonce to use crypto into content of cache. To generate: \FcPhp\Crypto\Crypto::getNonce() * @param string $pathKeys Path to save keys crypto * @return FcPhp\Cache\Interfaces\ICache */ $cache = CacheFacade::getInstance(string|array $cacheRepository, string $nonce = null, string $pathKeys = null); /* To use with Redis ========================= */ $redis = [ 'host' => '127.0.0.1', 'port' => '6379', 'password' => null, 'timeout' => 100, ]; $cache = CacheFacade::getInstance($redis); /* To use with Redis and crypto ========================= */ $redis = [ 'host' => '127.0.0.1', 'port' => '6379', 'password' => null, 'timeout' => 100, ]; $cache = CacheFacade::getInstance($redis, Crypto::getNonce(), 'path/to/keys'); /* To use with file ========================= */ $cache = CacheFacade::getInstance('path/to/cache'); /* To use with file and crypto ========================= */ $cache = CacheFacade::getInstance('path/to/cache', Crypto::getNonce(), 'path/to/keys'); /** * Method to create new cache * * @param string $key Key to name cache * @param mixed $content Content to cache * @param int $ttl time to live cache * @return FcPhp\Cache\Interfaces\ICache */ $cache->set(string $key, $content, int $ttl) :ICache /** * Method to verify if cache exists * * @param string $key Key to name cache * @return bool */ $cache->has(string $key) :bool /** * Method to verify/read cache * * @param string $key Key to name cache * @return mixed */ $cache->get(string $key) /** * Method to delete cache * * @param string $key Key to name cache * @return void */ $cache->delete(string $key) :void /** * Method to clean old caches * * @return FcPhp\Cache\Interfaces\ICache */ $cache->clean() :ICache