Download the PHP package daraniya/cache-graph without Composer
On this page you can find all versions of the php package daraniya/cache-graph. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download daraniya/cache-graph
More information about daraniya/cache-graph
Files in daraniya/cache-graph
Package cache-graph
Short Description Laravel cache dependency graph and intelligent cache invalidation package
License MIT
Informations about the package cache-graph
Laravel Cache Graph
A small, high-performance Laravel cache dependency graph and intelligent tagless cache invalidation package.
Why Cache Graph?
Laravel cache tags are incredibly useful, but they are not supported by the file, database, dynamodb, or apc cache drivers.
daraniya/cache-graph solves this by introducing a tagless cache dependency graph. It tracks which cache keys depend on which underlying data sources (e.g., specific models, DB tables, API queries). When a source changes, it invalidates all direct and transitive dependent cache keys recursively without needing native cache tag support.
Key Features in v0.1.0
- Tagless Cache Invalidation: Works out of the box on any Laravel cache driver.
- Deep Dependency Chains: Supports recursive invalidations (e.g.,
keyCdepends onkeyBwhich depends onkeyAwhich depends onsourceX). - Multiple Storage Engines:
- JSON/NDJSON (Default): Optimized append-only JSON event log with a small, compiled manifest and exclusive file locking (
flock). - Redis: Ultra-fast in-memory set and hash storage for high-concurrency production environments.
- Database: Standard query builder-driven storage, perfect for unified SQL architectures.
- JSON/NDJSON (Default): Optimized append-only JSON event log with a small, compiled manifest and exclusive file locking (
- Detailed Overhead Metrics:
- Storage Estimation: Estimates memory/storage footprint using precise serialization checks.
- Timings: Tracks
average,max,p95, and total count for operations (get,put,remember,invalidate,flush).
- Aesthetic CLI Reporter: Inspect your cache graph metrics instantly with a single artisan command.
Installation
Requirements
- PHP 8.1+
- Laravel 10, 11, 12, or 13
Install the package via Composer:
If you plan to use the Database driver, publish and run the migrations:
Publish the config file:
Configuration
The config file is published at config/cache-graph.php:
Disable graph tracking in production without changing application code:
When disabled, get, put, remember, and forget pass through to Laravel's cache. Dependency tracking, invalidation, metrics, and graph storage writes are skipped.
Usage
1. Retrieve & Cache with Dependencies (remember)
2. Standard Cache Operations (get & put)
3. Register Edges Manually (dependsOn)
4. Smart Recursive Invalidation (invalidateSource)
Invalidating a dependency source will automatically forget all associated cache keys and trace downstream dependencies.
Metric & Storage Formulas
Storage Overhead Estimation
The total storage overhead of a cache key in the graph is estimated as:
$$\text{Estimated Storage} = \text{Payload Bytes} + \text{Metadata Bytes} + \text{Dependency Edges Bytes} + \text{Reverse Index Bytes}$$
- Payload Bytes: The length of the serialized cache value (
strlen(serialize($value))). - Metadata Bytes: Overhead of storing key metadata (TTL, creation time, size counters).
- Dependency Edges Bytes: Bytes consumed by tracking links from key to dependency list.
- Reverse Index Bytes: Bytes consumed by tracking links in reverse lookup index (source to key list).
Operation Timings
The package tracks time elapsed in milliseconds for the following operations:
getputrememberinvalidateflush
Stats computed include average, max, 95th percentile (p95), and total operation count.
CLI Report Command
Run the report command to print a beautiful, structured overview of your cache graph:
If CACHE_GRAPH_ENABLED=false, the command exits successfully and reports that tracking is disabled.
Example CLI Output:
License
This package is open-sourced software licensed under the MIT license.