Download the PHP package drift/react-key-value without Composer
On this page you can find all versions of the php package drift/react-key-value. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download drift/react-key-value
More information about drift/react-key-value
Files in drift/react-key-value
Package react-key-value
Short Description Lightweight library that provides dynamic and smart local cache to your ReactPHP applications.
License MIT
Homepage https://github.com/driftphp/reactphp-key-value
Informations about the package react-key-value
ReactPHP key-value cache
Just a simple key-value local cache for your ReactPHP projects
Set a key
You can set a value given a key in this cache. As simple as it sounds.
Define TTL
You can add a TTL for this key. After n seconds, this key will be automatically deleted.
Get a key
You can get a value from this cache by using the key. If the value is present inside the cache, this one will be returned with no transformations. Otherwise, null will be returned.
Refresh TTL on access
TTL can offer a proper way to basically clean elements that are almost not used. By defining a value in TTL, by default this key will be deleted after n seconds, no matter how many times this key has been requested until this moment. If we want to automatically refresh this TTL each time we access to a key, we can use this feature.
In this example, we can see that the key is defined with a TTL of 2 seconds
and is requested each second, enabling the refreshTTL
flag. In normal
circumstances, after 2 seconds the get
method should return null, but because
we are forcing the cache to refresh this TTL when we access the key, as long as
we don't have time gaps larger than 2 seconds, our key will always be available.
With this strategy you will only save locally these values used most frequent, finding this way a nice equilibrium between cache efficiency and storage size.
Delete a key
You can manually delete a key. If the key is not found inside the cache, nothing will happen.
Using the middleware
In your applications you might want to use this cache as a simple and thin middleware layer, so you can easily enable and disable without changing your domain implementation.
Well, then you should use the KeyValueCacheMiddleware
class, acting as an
uncoupled piece in the middle.
So, having this original code in PHP
You could easily add a simple layer that caches during 10 minutes, updating the key freshness each time this one es requested.
All versions of react-key-value with dependencies
react/event-loop Version ^1.0 || ^0.5 || ^0.4 || ^0.3.5
react/promise Version ^2.7 || ^1.2.1
drift/react-functions Version ^0.1