paquettg / leaguewrap

League of Legend API wrapper
MIT License
67 stars 28 forks source link

Caching with Redis? #107

Closed JoJota closed 8 years ago

JoJota commented 8 years ago

Can someone give me an example of how external caching works (especially with redis)? I have set up a redis server and connected with predis. I am able to execute the following example:

require "predis/autoload.php";
Predis\Autoloader::register();

try {$myClient = new Predis\Client(array(
        'scheme'    => 'unix',
        'path'      => '/home/.redis/sock'
    ));

}
catch (Exception $e) {
    die($e->getMessage());
}

// sets message to contian "Hello world"
$redis->set(';message';, ';Hello world';);

// gets the value of message
$value = $redis->get('message');

// Hello world
print($value);

But how can I implement this in Leaguewrap? What type of variable does $myCache have to be? $api->remember(60, $myCache);

I am still learning PHP, so any help would be very much appreciated.

dnlbauer commented 8 years ago

For caching with redis, you need to write a class implementing \Leaguewrap\CacheInterface.php and then pass an instance of that class to the api (If you give the api a cache instance, it will use this for caching instead of its own memcached implementation). You should have a look at \Leaguewrap\Cache.php and how it implements CacheInterface to communicate with Memcached as a reference.

Feel free to share your result. Im interested in caching with redis as well :)