Download the PHP package cmatosbc/mnemosyne without Composer
On this page you can find all versions of the php package cmatosbc/mnemosyne. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cmatosbc/mnemosyne
More information about cmatosbc/mnemosyne
Files in cmatosbc/mnemosyne
Package mnemosyne
Short Description PSR compliant caching system using PHP attributes.
License gpl-3.0-or-later
Informations about the package mnemosyne
Mnemosyne - PHP Attribute-based Caching Library
Mnemosyne is a powerful and flexible caching library for PHP 8.0+ that uses attributes to simplify cache management. It provides automatic caching and invalidation based on method attributes, making it easy to add caching to your application.
Features
- Attribute-based caching configuration
- Automatic cache key generation
- Parameter-based cache keys with interpolation
- Automatic and manual cache invalidation
- Cache tags for group invalidation
- PSR-16 (SimpleCache) compatibility
- Flexible cache key templates
- Smart serialization handling:
- Automatic serialization of complex objects
- Optional raw storage for simple data types
- Full control over serialization behavior
Installation
Usage
To use Mnemosyne in your classes, you must:
- Use the
CacheTrait
in your class - Inject a PSR-16 compatible cache implementation
- Apply the
Cache
attribute to methods you want to cache
Basic Usage
Serialization Control
The Cache
attribute allows you to control how values are stored in cache:
Custom Cache Keys
Cache Invalidation
Automatic Invalidation
Manual Invalidation
Cache Tags
Cache tags allow you to group related cache entries and invalidate them together. This is useful for managing cache dependencies and bulk invalidation.
Tags support parameter interpolation just like cache keys, allowing you to create dynamic tag names. When a tag is invalidated, all cache entries associated with that tag are automatically removed.
Best Practices
-
Split cached methods into two parts:
- A public method with the Cache attribute that handles caching
- A private method with the actual implementation
- Use meaningful cache keys that reflect the data structure
- Set appropriate TTL values based on data volatility
- Use cache invalidation when data is modified
- Consider using cache tags for group invalidation
Testing
The library includes comprehensive PHPUnit tests. Run them with:
License
This project is licensed under the GNU General Public License v3.0 or later - see the LICENSE file for details. This means you are free to use, modify, and distribute this software, but any modifications must also be released under the GPL-3.0-or-later license.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.