lss/yacache

Lightweight Cache (PSR-16 compatible)

1.2.0 2020-12-03 21:41 UTC

This package is auto-updated.

Last update: 2024-10-29 05:40:24 UTC


README

A minimal PSR16 compatible cache library for PHP 7.4+

The goals of this project are

  • Minimalism: as little code as possible, only the barest necessary features, as few dependencies as possible.
  • Performance: Strips out all but essential features in the main execution flow so that it runs really fast.
  • (almost) Standards Compliance: PSR-16 does not have strict typing (yet!?). The CacheInterface is mostly duck-type compatible with PSR-16 (No support for DateInterval $ttl)
  • adds some tiny and optional utility functions to ease API development eg increment() for rate limiters, remember() to remove boilerplate lines of code
  • Quality: 100% unit test coverage, phpstan max strict, strict_types=1

Why another cache when there are already so many that are very good?

Pull requests welcome, but bear in mind the above project goals. If you have more complex needs, the other (better written, better supported, more mature) projects mentioned above will be a better choice for you.

Installation

composer require LSS\YACache

How to use

use LSS\YACache\RedisCache;

$redis = new \Redis('127.0.0.1');
$cache = new RedisCache($redis);
$value = $cache->remember('another key', 100, function () use ($database) { return $database->someExpensiveQueryResult(); });

Browse the /src directory for more drivers