PHP code example of zheltikov / php-memoize-redis
1. Go to this page and download the library: Download zheltikov/php-memoize-redis library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zheltikov / php-memoize-redis example snippets
heltikov\Memoize\RedisCache;
use function Zheltikov\Memoize\wrap;
// Create a new instance
$cache = new RedisCache();
$cache->setHashName('my_hash_name'); // the hash used to cache the results
// Configure the Redis object
$cache->getRedis()
// For example, change the serializer to be used.
// By default, `Redis::SERIALIZER_PHP` will be used by the cache.
->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_JSON);
// or you can supply your own Redis object
$my_redis_object = new Redis();
// do some configuration here...
// set it to the cache
$cache->setRedis($my_redis_object);
// finally, use it when memoizing:
function my_expensive_function() { /* ... */ }
$wrapped = wrap('my_expensive_function', $cache);
// enjoy!
shell
$ composer