Download the PHP package schoolpalm/cache-store without Composer
On this page you can find all versions of the php package schoolpalm/cache-store. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download schoolpalm/cache-store
More information about schoolpalm/cache-store
Files in schoolpalm/cache-store
Package cache-store
Short Description A context-aware cache abstraction layer for Laravel applications with multi-tenant and multi-school support.
License MIT
Informations about the package cache-store
CacheStore โ Context-Aware Cache for Laravel
CacheStore is a powerful, context-aware cache abstraction layer for Laravel applications. It goes beyond simple key-value storage by introducing multi-tenant, multi-school, and custom context scoping โ making it ideal for SaaS platforms, school management systems, and any application that needs isolated cache namespaces.
Features
- ๐ข Context-Aware Caching โ Automatically scope cache keys by tenant, school, or custom context
- ๐ Multiple Drivers โ Array, File, Database, Redis, and Laravel Cache drivers included
- ๐ Pluggable Architecture โ Implement your own drivers via the
CacheDrivercontract - ๐ Serialization โ Automatic PHP serialization for complex types (arrays, objects)
- โก Atomic Operations โ Increment/decrement bypass serialization for raw numeric operations
- ๐งช Test-Ready โ Array driver for testing, trait-based test helpers
- ๐ฆ Auto-Discovery โ Laravel package auto-discovery for service provider and facade
Quick Start
Table of Contents
- Installation
- Configuration
- Usage
- Drivers
- Context-Aware Caching
- Testing
- Driver Contract
- Requirements
- Changelog
- Contributing
- Security
- License
Installation
You can install the package via Composer:
Service Provider Discovery
Laravel will auto-discover the CacheStoreServiceProvider. If you have disabled package discovery, register it manually in config/app.php:
Facade
The CacheStore facade is also auto-discovered. If needed, register it manually:
Publishing Configuration
Configuration
The package configuration file config/cache-store.php is automatically merged with your application's config.
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
driver |
string |
'file' |
Default cache driver |
key_separator |
string |
':' |
Separator for context key segments |
prefix |
string |
'schoolpalm' |
Global prefix for all cache keys |
context.tenant |
bool |
true |
Enable tenant context scoping |
context.school |
bool |
true |
Enable school context scoping |
drivers.file.path |
string |
storage_path('framework/cache') |
File cache storage path |
drivers.redis.connection |
string |
'default' |
Redis connection name |
drivers.database.table |
string |
'cache_store' |
Database cache table name |
Usage
Basic Cache Operations
Complex Data Types
Remember Pattern
Drivers
CacheStore ships with five built-in drivers, each optimized for different use cases:
| Driver | Class | Backend | Use Case |
|---|---|---|---|
| Array | ArrayCacheDriver |
PHP memory | Testing, local development |
| File | FileCacheDriver |
File system | Single-server, small apps |
| Database | DatabaseCacheDriver |
SQL database | Persistent, multi-server |
| Redis | RedisCacheDriver |
Redis | High-performance, distributed |
| Laravel | LaravelCacheDriver |
Any Laravel store | Bridge to existing cache |
Using a Specific Driver
Writing a Custom Driver
Implement the CacheDriver contract to create your own driver:
Context-Aware Caching
The standout feature of CacheStore is context-aware caching โ automatically scoping cache keys by tenant, school, or any custom context.
How It Works
When you use a context, CacheStore prefixes your cache keys with context identifiers:
This ensures that the same key name in different contexts never collides.
Usage
Configuring Context
You can enable/disable context segments in the config:
When disabled, the corresponding context segment is omitted from the cache key.
Key Building Logic
The cache key is built using the following pattern:
Where:
{prefix}โ Global prefix from config (schoolpalm){tenant}โ Tenant identifier (ifcontext.tenantis enabled){school}โ School identifier (ifcontext.schoolis enabled){key}โ Your cache key- Segments are joined using the configured
key_separator
Testing
CacheStore makes testing a breeze with its Array driver and shared test traits.
Running Tests
Test Traits
Use the CacheDriverBehaviour trait to run a comprehensive test suite against any driver:
This automatically tests:
- Store & retrieve values
- Store & retrieve integer values
- Return default value for missing keys
- Key existence checks
- Overwrite existing values
- Forget operations
- Array storage
- Object storage
- Boolean storage
- Forever storage
- Add (unique key) operations
- Pull operations
- Pull returns default for missing keys
- Increment / Decrement
- Many operations
- Many returns null for missing keys
- Flush operations
Creating a Custom Driver Test
Note: Include
tests/Support/cacheDriverTests.phpin your test file to execute the shared test suite.
Driver Contract
All cache drivers must implement the SchoolPalm\CacheStore\Contracts\CacheDriver interface:
Serialization Behavior
Drivers handle serialization automatically via CacheSerializer:
| Value Type | Storage Format | Retrieval |
|---|---|---|
string |
Stored as-is | Returned as string |
int |
Stored as string | Cast back to int |
float |
Stored as string | Cast back to float |
bool |
PHP serialized (b:1; / b:0;) |
Unserialized to bool |
array |
PHP serialized | Unserialized to array |
object |
PHP serialized | Unserialized to original class |
null |
Not stored | Default value returned |
Note:
increment()anddecrement()bypass serialization for raw numeric operations at the storage layer.
Requirements
- PHP: ^8.2
- Laravel: ^12.0 (Illuminate\Support and Illuminate\Cache)
- Database Driver: Requires a database connection when using the
databasecache driver - Redis Driver: Requires
predis/predisorphpredisextension when using therediscache driver
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Development Setup
- Clone the repository
- Run
composer install - Run
composer buildto set up the testbench workbench - Run
composer testto execute tests
Code Style
This package follows the PSR-12 coding standard.
Security
Please see SECURITY for our security policy.
Credits
- SchoolPalm
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
Built with โค๏ธ by SchoolPalm for the Laravel community