Matomo Cache

A fast multi-backend PHP caching library built on Doctrine cache, extracted from Matomo.

Library
Composer
v3.0.0
38stars
LGPL-3.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
31/100Needs Attention
Development Activity4
Maintenance20
Community28
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
70/100Good
Architecture78
Code Quality72
Innovation60
Learning Curve72

Matomo Cache is a PHP caching library built on top of Doctrine cache and developed by the Matomo analytics team, where fetching hundreds of cache entries in a single request made raw speed a first-class concern. It exposes a small, consistent API over a range of interchangeable backends so you can tune caching behaviour per environment without touching call sites.

Beyond simple key/value storage it provides eager, lazy, and transient caching strategies plus decorators for key prefixing, default timeouts, and chaining backends together, letting you compose a caching layer that fits your application’s read patterns.

What You Get

  • A unified Cache interface over array, file, null, Redis, and chained backends
  • Eager and Lazy caching strategies for different read/write access patterns
  • A Transient (single-request) cache for very hot in-request data
  • Decorators for key prefixing, default timeouts, and backend chaining
  • A backend factory that constructs the configured store from a simple config array

Common Use Cases

  • Caching expensive query or computation results across requests
  • Layering a fast in-memory cache in front of a slower persistent backend
  • Prefixing keys so multiple apps can share one Redis instance safely
  • Disabling caching in development with the null backend

Under The Hood

Architecture - The library centres on the Matomo\Cache\Cache interface, implemented by Eager and Lazy strategies that delegate to a Backend obtained from src/Backend/Factory. Backends (ArrayCache, File, Redis, NullCache, Chained) all conform to a common Backend contract, and decorator backends (KeyPrefixDecorated, DefaultTimeoutDecorated, BaseDecorator) wrap another backend to add cross-cutting behaviour. Transient provides an in-request store. This layered strategy/backend/decorator split lets callers depend only on the Cache interface while the concrete storage is swapped by configuration.

Tech Stack - Pure PHP (>=7.2) with PSR-4 autoloading under Matomo\Cache, built on the matomo/doctrine-cache-fork dependency for the underlying Doctrine cache drivers. Redis support relies on the phpredis extension. Tests run under PHPUnit (phpunit.xml present).

Code Quality - The code is cleanly namespaced and small, with a dedicated tests/ directory and a committed composer.lock. Responsibilities are well separated across strategies, backends, and decorators, following the decorator pattern consistently. It is mature and stable rather than actively evolving.

API Design - The public surface is intentionally minimal: fetch, save, contains, delete, and flush on the Cache interface, with construction handled by the factory. Swapping backends is a config change, and decorators compose transparently, so ergonomic usage requires very little boilerplate.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search