woocommerce-paypal-payments/modules.local/cache-module
2020-04-13 11:52:50 +03:00
..
src add caching module 2020-04-10 12:55:50 +03:00
tests/PHPUnit add error response object 2020-04-13 11:52:50 +03:00
composer.json add caching module 2020-04-10 12:55:50 +03:00
LICENSE.md add caching module 2020-04-10 12:55:50 +03:00
module.php add caching module 2020-04-10 12:55:50 +03:00
phpunit.xml.dist add caching module 2020-04-10 12:55:50 +03:00
README.md add caching module 2020-04-10 12:55:50 +03:00
services.php add caching module 2020-04-10 12:55:50 +03:00

Cache Module

This module provides a PSR compatible integration of the WordPress caching system.

How to use it

composer require inpsyde/cache-module

Lets say, you class requires a PSR CacheInterface. In you build factory, you could do something like the following:

'app.foo' => function(ContainerInterface $container) : Foo {
    $provider = $container->get('cache.provider');
    $cache = $provider->cacheForKey('your-group-key');
    return new Foo($cache);
}

The Provider

The provider comes with three methods:

CacheProviderInterface::cacheForKey(string $key):

Returns an implementation for wp_cache_get() etc. $key acts as the group.

CacheProviderInterface::transientForKey(string $key):

Returns an implementation for set_transient() etc. $key acts as a prefix for the cache keys.

CacheProviderInterface::cacheOrTransientForKey(string $key):

There are cases, where you want the object cache, but you can't rely on its present. While set_transient() falls back to the object cache, where it is present, you might want to be more specific. This method would allow you to get an interface back, which itself relies on object cache (if that is possible) or returns the transient implementation.