Download the PHP package solophp/cache without Composer
On this page you can find all versions of the php package solophp/cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download solophp/cache
More information about solophp/cache
Files in solophp/cache
Package cache
Short Description PSR-16 compliant cache library with pluggable adapters
License MIT
Informations about the package cache
PSR-16 Cache Library
A flexible, PSR-16 compliant cache library with pluggable adapters for PHP 8.1+.
Features
- Full PSR-16 (Simple Cache) compliance
- Pluggable adapter architecture
- File-based cache adapter
- Redis cache adapter
- Thread-safe file operations with
LOCK_EX - Automatic expiration handling
- Support for TTL as integer seconds or DateInterval
Installation
For Redis support, ensure you have the Redis PHP extension installed:
Usage
File Cache
Redis Cache
Multiple Operations
Using DateInterval for TTL
Adapters
FileAdapter
File-based cache implementation suitable for low to medium load applications.
Constructor Parameters:
$cacheDirectory(string): Directory path for storing cache files$mode(int): Error handling mode (optional, default: MODE_THROW)
Features:
- Two error handling modes:
FileAdapter::MODE_THROW- Throws exceptions on errors (default)FileAdapter::MODE_FAIL- Returns false/default on errors (graceful degradation)
- Optimized batch operations:
- Automatic deduplication of keys in batch operations
- Early return for empty arrays
- Graceful error handling in batch operations
- Garbage collection method
gc()for manual cleanup of expired files - Refactored cache loading with centralized
loadCacheData()method - Automatic directory creation with 0755 permissions
- Thread-safe operations with file locking (LOCK_EX)
- Automatic cleanup of expired entries on read operations
- Uses MD5 hashing for file names
- Runtime mode switching with
setMode()method
Usage with error modes:
Limitations:
- Not suitable for high-performance or distributed systems
- Consider Redis or Memcached for high-load scenarios
RedisAdapter
Redis-based cache implementation for high-performance and distributed applications.
Constructor Parameters:
$redis(Redis): Connected Redis instance$mode(int): Error handling mode (optional, default: MODE_THROW)$prefix(string): Key prefix for namespace isolation (optional, default:cache:)
Features:
- Optimized batch operations using Redis native commands (mGet, mSet, del)
getMultiple()uses single mGet call instead of N individual getssetMultiple()uses atomic mSet when no TTL is specifieddeleteMultiple()uses single del call with array of keys
- Manual serialization — correctly handles all PHP types including
false - Production-safe
clear()— uses SCAN instead of KEYS to avoid blocking Redis - Two error handling modes:
RedisAdapter::MODE_THROW- Throws exceptions on errors (default)RedisAdapter::MODE_FAIL- Returns false/default on errors (graceful degradation)
- Automatic deduplication of keys in batch operations
- Configurable key prefix for multi-app namespace isolation
- Native Redis TTL support
- Runtime mode switching with
setMode()method - Suitable for distributed systems
Key Validation
Both adapters enforce PSR-16 key requirements:
- Keys cannot be empty
- Only alphanumeric characters, underscores, dots, colons, and hyphens are allowed
- Pattern:
/^[a-zA-Z0-9_.:-]+$/ - Colons (
:) are supported as the standard separator for cache keys (Redis, Memcached conventions) - Hyphens (
-) are supported for UUID keys
Example keys:
user:123:profilecache:session:abc123app.config.database550e8400-e29b-41d4-a716-446655440000
Invalid keys will throw Solo\Cache\Exception\InvalidArgumentException.
Exceptions
The library provides PSR-16 compliant exceptions:
Solo\Cache\Exception\InvalidArgumentException- Invalid cache keys or argumentsSolo\Cache\Exception\CacheException- Cache operation failures
Requirements
- PHP 8.1 or higher
- psr/simple-cache ^3.0
- ext-redis (for Redis adapter)
License
MIT