Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. PHP
  3. Metaphore

Metaphore

MITPHPv2.0.1

A PHP library that prevents cache stampedes using a semaphore to protect backend systems from dogpile effects.

GitHubGitHub
99 stars9 forks0 contributors

What is Metaphore?

Metaphore is a PHP library designed to defend against cache stampedes, also known as the dogpile effect, which occurs when multiple requests simultaneously attempt to regenerate expired cache content, overwhelming backend resources like databases. It uses a semaphore-based locking mechanism to ensure only one request regenerates the cache while others serve stale content, maintaining performance and stability.

Target Audience

PHP developers building high-traffic web applications that rely on caching (e.g., using Memcached or Redis) and need to prevent database overload during cache expiration events.

Value Proposition

Developers choose Metaphore for its simple, reliable semaphore-based approach to cache slam defense, which includes configurable TTL control, separate store management for values and locks, and event handling for edge cases like no stale cache scenarios.

Overview

Cache slam defense using a semaphore to prevent dogpile effect.

Use Cases

Best For

  • Preventing database slams when cache expires simultaneously for many users on high-traffic PHP sites.
  • Implementing stale-while-revalidate caching patterns in PHP applications to serve stale content gracefully during cache regeneration.
  • Managing cache locks and values in different backends, such as using MySQL for locks and Memcached for cache values.
  • Adding custom logging or result modification when no stale cache is available via event hooks.
  • Configuring advanced cache TTL settings with grace periods and lock durations for fine-tuned control.
  • Defending against the Slashdot effect or dogpile effect in PHP-based content management systems or APIs.

Not Ideal For

  • Applications requiring zero stale content serving during cache regeneration, as Metaphore always serves stale cache to concurrent requests.
  • Projects using non-PHP backend languages or polyglot microservices, since Metaphore is PHP-specific.
  • Environments where built-in distributed lock support across data centers is needed, as Metaphore relies on external stores like MySQL or Memcached for locks.
  • Teams wanting out-of-the-box integration with modern PHP frameworks without additional configuration work.

Pros & Cons

Pros

Semaphore-Based Locking

Prevents concurrent cache regeneration by allowing only one request to generate new content at a time, directly addressing the dogpile effect as described in the README's problem-solution overview.

Graceful Stale Serving

Serves stale cached content to subsequent requests while new content is generated, similar to HTTP's stale-while-revalidate, ensuring performance and stability under high load.

Configurable TTL Control

Offers advanced TTL settings with grace periods and lock durations via the Ttl object, allowing fine-tuned control over cache behavior, as shown in the usage examples.

Separate Store Management

Enables cache values and locks to be stored in different backends, such as Memcached for values and MySQL for locks, increasing flexibility for complex deployments.

Cons

External Store Dependency

Requires setting up and maintaining external cache stores like Memcached or Redis, adding infrastructure complexity and potential points of failure.

PHP-Only Limitation

Limited to PHP applications, making it unsuitable for projects using other languages or requiring cross-platform cache coordination.

Default Lock TTL Shortfalls

The default lock TTL of 5 seconds might be too short for long-running cache generation tasks, risking multiple regenerations if not manually adjusted.

Frequently Asked Questions

Quick Stats

Stars99
Forks9
Contributors0
Open Issues2
Last commit2 years ago
CreatedSince 2013

Tags

#locking#caching#redis#cache-stampede#backend#php#semaphore#memcached#performance

Built With

M
MySQL
P
PHP
M
Memcached
R
Redis

Included in

PHP32.5k
Auto-fetched 8 hours ago

Related Projects

Doctrine CacheDoctrine Cache

Doctrine Cache component

Stars7,856
Forks210
Last commit11 months ago
CacheToolCacheTool

CLI App and library to manage apc & opcache.

Stars1,826
Forks158
Last commit7 months ago
StashStash

The place to keep your cache.

Stars963
Forks131
Last commit8 months ago
LockLock

Popular PHP library for serialized execution of critical code in concurrent situations

Stars948
Forks92
Last commit6 months ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub