A PHP library that prevents cache stampedes using a semaphore to protect backend systems from dogpile effects.
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.
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.
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.
Cache slam defense using a semaphore to prevent dogpile effect.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
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.
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.
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.
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.
Requires setting up and maintaining external cache stores like Memcached or Redis, adding infrastructure complexity and potential points of failure.
Limited to PHP applications, making it unsuitable for projects using other languages or requiring cross-platform cache coordination.
The default lock TTL of 5 seconds might be too short for long-running cache generation tasks, risking multiple regenerations if not manually adjusted.