matthiasmullie/scrapbook
Scrapbook is a PHP caching library that wraps PSR-6/PSR-16 cache backends with adapters, multi-cache fallbacks, buffering and stampede protection. Use it to add fast, resilient caching with minimal code changes across files, memory or Redis stores.
Start by installing via Composer: composer require matthiasmullie/scrapbook. Then instantiate a cache adapter (e.g., new \ MatthiasMullie\Scrapbook\Adapters\Redis($redisClient)) and wrap it in the main Cache class. The simplest use case is basic get/set operations: $cache->set('key', $data); $data = $cache->get('key');. Review the Adapters namespace to understand available backend options—Redis and Memcached are most common in production. Check out examples/ in the repo for quick integration snippets.
$cache->get('key', null, true) to enable automatic stampede protection via getWithStampedeProtection(), which locks cache regeneration for heavy operations.$cache->transaction(function() use ($cache) {
$cache->set('a', 1);
$cache->set('b', 2);
});
TaggableAdapter): Wrap adapters like ArrayAdapter or Redis with TaggableAdapter to invalidate groups:
$cache = new \Matthiasmullie\Scrapbook\Adapters\Taggable($adapter);
$cache->set('post:123', $data, 'posts');
$cache->flushByTag('posts');
$cache->set('key', $value, 3600);.TaggableAdapter, or tag-related methods will silently fail or throw.igbinary or json), as mismatches can corrupt cached data across clients.null: get() returns null both for cache misses and when null is the stored value. Use has() before get() or check explicitly if null is valid data.How can I help you explore Laravel packages today?