Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Sergey Zhuk:
Promise-Based Cache With ReactPHP
Sep 20, 2017 @ 15:11:55

Sergey Zhuk has written up a tutorial showing you how to implement promise-based caching with ReactPHP, a continuation of a previous post.

In the previous article, we have already touched caching (when caching DNS records). It is an asynchronous promise-based Cache Component. The idea behind this component is to provide a promise-based CacheInterface and instead of waiting for a result to be retrieved from a cache the client code gets a promise. If there is a value in a cache the fulfilled with this value promise is returned. If there is no value by a specified key the rejected promise returns.

He starts by defining the caching interface and how it would look in use to set/get a cache value. He shows how to update this with a "done" handler to output the value when the get is complete. He continues on showing how to use a fallback handler: either "otherwise" or "then". He also shows how these can be chained together to make more complex operations. The post ends with an example of this caching component in action and links to other library that use the same ideas.

tagged: promise cache reactphp get set tutorial component interface

Link: http://seregazhuk.github.io/2017/09/15/reactphp-cache/


Trending Topics: