Download the PHP package julienlinard/php-cache without Composer
On this page you can find all versions of the php package julienlinard/php-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download julienlinard/php-cache
More information about julienlinard/php-cache
Files in julienlinard/php-cache
Package php-cache
Short Description Système de cache moderne et sécurisé pour PHP 8+ avec support de multiples drivers (File, Redis, Memcached, Array), tags, TTL et invalidation
License MIT
Homepage https://github.com/julien-lin/php-cache
Informations about the package php-cache
PHP Cache
🇬🇧 Read in English
💝 Support the project
If this package is useful to you, consider becoming a sponsor to support the development and maintenance of this open source project.
A modern and secure caching system for PHP 8+ with support for multiple drivers (File, Redis, Memcached, Array), tags, TTL, and invalidation.
🚀 Installation
Requirements: PHP 8.0 or higher
⚡ Quick Start
Basic Configuration
📋 Features
- ✅ Multiple Drivers: Array, File, Redis
- ✅ TTL (Time To Live): Automatic entry expiration
- ✅ Tags: Tag system for grouped invalidation
- ✅ Security: Key validation, protection against injections
- ✅ Secure Serialization: JSON usage with validation
- ✅ Multiple Operations: getMultiple, setMultiple, deleteMultiple
- ✅ Increment/Decrement: Support for numeric values
- ✅ Fluid Interface: Simple and intuitive API
📖 Documentation
Available Drivers
Array Driver (Memory)
The Array driver stores data in memory. Useful for testing and development.
File Driver (Disk)
The File driver stores data in files on the filesystem.
Redis Driver
The Redis driver requires the PHP Redis extension.
Basic Operations
Store a Value
Retrieve a Value
Check Existence
Delete a Value
Clear All Cache
Multiple Operations
Retrieve Multiple Values
Store Multiple Values
Delete Multiple Keys
Increment and Decrement
Pull (Retrieve and Delete)
Using a Specific Driver
Tag System
Tags allow grouping cache entries and invalidating them together.
Advanced Usage with CacheManager
Key Validation
The system automatically validates keys for security:
- ✅ Allowed characters: letters, numbers,
_,-,. - ✅ Maximum length: 250 characters
- ✅ Protection against path injections (
..,/,\)
Error Handling
🔒 Security
Implemented Security Measures
- Key Validation: Protection against path injections
- Secure Serialization: JSON usage with strict validation
- File Permissions: Permission control for File driver
- Atomic Writing: File driver uses temporary files to prevent corruption
- Input Validation: All entries are validated before storage
Best Practices
🧪 Tests
📝 Usage Examples
Database Query Caching
Cache with Tag Invalidation
View/Template Caching
Counter with Expiration
🤝 Integration with Other Packages
With doctrine-php
📚 API Reference
Cache (Facade)
Cache::init(array $config): Initialize the managerCache::get(string $key, mixed $default = null, ?string $driver = null): Retrieve a valueCache::set(string $key, mixed $value, ?int $ttl = null, ?string $driver = null): Store a valueCache::has(string $key, ?string $driver = null): Check existenceCache::delete(string $key, ?string $driver = null): Delete a valueCache::clear(?string $driver = null): Clear cacheCache::increment(string $key, int $value = 1, ?string $driver = null): IncrementCache::decrement(string $key, int $value = 1, ?string $driver = null): DecrementCache::pull(string $key, mixed $default = null, ?string $driver = null): Retrieve and deleteCache::tags(string|array $tags, ?string $driver = null): Create tagged cacheCache::driver(?string $driver = null): Get a driver
CacheInterface
All drivers implement CacheInterface with the following methods:
get(string $key, mixed $default = null): mixedset(string $key, mixed $value, ?int $ttl = null): booldelete(string $key): boolhas(string $key): boolclear(): boolgetMultiple(array $keys, mixed $default = null): arraysetMultiple(array $values, ?int $ttl = null): booldeleteMultiple(array $keys): intincrement(string $key, int $value = 1): int|falsedecrement(string $key, int $value = 1): int|falsepull(string $key, mixed $default = null): mixed
🐛 Troubleshooting
File Driver Not Working
Check that the cache directory exists and is writable:
Redis Driver Not Connecting
- Check that Redis extension is installed:
php -m | grep redis - Check that Redis is running:
redis-cli ping - Check connection parameters in configuration
"Invalid Key" Error
Keys must follow this format:
- Allowed characters:
a-z,A-Z,0-9,_,-,. - Maximum length: 250 characters
- No relative paths (
..,/,\)
📝 License
MIT License - See the LICENSE file for more details.
🤝 Contributing
Contributions are welcome! Feel free to open an issue or a pull request.
📧 Support
For any questions or issues, please open an issue on GitHub.
💝 Support the project
If this package is useful to you, consider becoming a sponsor to support the development and maintenance of this open source project.
Developed with ❤️ by Julien Linard
All versions of php-cache with dependencies
ext-json Version *