PHPackages                             whales/cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. whales/cache

ActiveLibrary[Caching](/categories/caching)

whales/cache
============

Caching library

0.2.0(11y ago)016PHP

Since Oct 31Pushed 11y ago1 watchersCompare

[ Source](https://github.com/jonwhelan/cache)[ Packagist](https://packagist.org/packages/whales/cache)[ RSS](/packages/whales-cache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

\#Cache ##Examples ###Stampede Protection ####Object Instantiation

```
	// Service in need of caching and stampede protection
	$callableService = function ($key) { return 'resourceIntensiveData'; };

	// Would need to be database-backed lock to actual work in the example
	// since the InMemoryLock has a per request lifecycle.
	$lock = new Cache\StampedeProtection\Locks\InMemoryLock;

	$memcached = new \Memcached();
	$memcached->addServer('127.0.0.1', 11211);

	$transientCache = new Cache\Maps\MemcachedCacheMap($memcached);

	// Acts as stale cache while service is processing data
	$persistentCache = new Cache\Maps\PdoCacheMap(
		new \PDO('mysql:host=localhost;dbname=test'),
		'cache'
	);
```

\####Object Composition

```
	$cachedService = new CallableServiceCachingDecorator(
		new MutexLockAcquiringDecorator(
			$callableService,
			$lock,
			$persistentCache
		),
		new LockReleaseOnSettingCacheMap(
			new LinkedNodeCacheMap(
				$transientCache,
				new LockAffectedCacheMap(
					$persistentCache,
					$lock
				)
			),
			$lock
		)
	);

	$data = call_user_func($cachedService, 'key1234');
```

\####Explanation

**Assumption**: The `$persistentCache` is primed so that there will always be some data returned even while the new data is being retrieved/regenerated.

- When a request comes into `$cachedService` it will attempt to find the item in the cache
    - The call to `find` will get passed on through:
        - `LockReleaseOnSettingCacheMap`, which delegates to:
        - `LinkedNodeCacheMap`
            - Here it will first check the `$transientCache` and either:
                - **Hit**, in which case it will return the cached value all the way back up to the original caller.
                - **Miss** and then:
                    - Check the `$persistentCache`, which is primed and *should* result in a hit, however since the `LockAffectedCacheMap` is wrapping the `$persistentCache` it will report a cache miss since the lock is available (i.e. nobody else is currently working on regenerating the data for the cache)
                    - The cache miss is then propogated all the way back up to `CallableServiceCachingDecorator`.
    - Since the iterator returned from `find` is empty, the code then needs to call into the actual service to retrieve the fresh data.
        - The call to the service will pass through the `MutexLockAcquiringDecorator` object which will acquire the lock and let all future requests to the service know that someone is currently retrieving the data from the original datasource and regenerating the new cache data.
        - While the lock is held, all future requests will retrieve data from the stale `$persistentCache`. Remember that since this is wrapped in the `LockAffectedCacheMap` and the lock is now **unavailable** the `$persistentCache` will now report a cache hit and return it's stale data.
    - After the service is called and the fresh data is returned back up to `CallableServiceCachingDecorator`, we then set the cache to reflect the new data.
    - The call to `set` passes through `LockReleaseOnSettingCacheMap` which delegates the setting to `LinkedNodeCacheMap` which then will add the new data to both the `$transientCache` and `$persistentCache` (future stale cache).
    - After setting the new values, the lock is then released.
    - Finally the fresh data is passed out to the top-level caller.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

4214d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b406f5c5133ed53f72b8868b03010a7c9fb2193d1cf1548480e01d7d7cef52b5?d=identicon)[jonwhelan](/maintainers/jonwhelan)

---

Top Contributors

[![jonwhelan](https://avatars.githubusercontent.com/u/7376957?v=4)](https://github.com/jonwhelan "jonwhelan (18 commits)")

---

Tags

cachecaching

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/whales-cache/health.svg)

```
[![Health](https://phpackages.com/badges/whales-cache/health.svg)](https://phpackages.com/packages/whales-cache)
```

###  Alternatives

[psr/simple-cache

Common interfaces for simple caching

8.1k727.3M2.1k](/packages/psr-simple-cache)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[tedivm/stash

The place to keep your cache.

9824.8M124](/packages/tedivm-stash)[spatie/blink

Cache that expires in the blink of an eye

1685.0M8](/packages/spatie-blink)[gregwar/cache

A lightweight file-system cache system

1084.5M22](/packages/gregwar-cache)[putyourlightson/craft-blitz

Intelligent static page caching for creating lightning-fast sites.

153471.5k29](/packages/putyourlightson-craft-blitz)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
