Download the PHP package lotestudio/model-cache without Composer
On this page you can find all versions of the php package lotestudio/model-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package model-cache
Laravel Model Cache
Under development! Use at your own risk!
A lightweight, convention-driven caching layer for Laravel Eloquent models. Automatically caches model query results with observer-based invalidation, request-level caching, and Artisan commands for management.
Designed to cache frequently accessed reference data like stores, price lists, categories, and roles. It's ideal for small datasets (under 50 records) that are read often but change rarely, dramatically reducing database queries and improving response times from ~5-10ms to under 1ms.
Use it when: you have lookup tables, reference data, or configuration-like models that are loaded on almost every request and don't change frequently.
Avoid it when: you're dealing with large tables (>100 records), frequently changing data, real-time requirements, or models with heavy JSON fields that consume significant memory.
Best for: Stores, price lists, categories, statuses, roles, and other "dictionary" tables that power your application's dropdowns, filters, and navigation.
Not suitable for: Orders, users, logs, products (if large), or any data that requires up-to-the-second accuracy.
The package includes automatic cache clearing via observers, request-level caching, Artisan commands, and full Eloquent model support — everything stays cached while maintaining Laravel's native behavior.
Features
- Automatic Caching — Cache model query results with configurable TTL and cache driver
- Observer-Based Invalidation — Automatically clears cache when models are saved, updated, deleted, or restored
- Request-Level Caching — Avoids redundant cache lookups within the same request
- Artisan Commands — Warm up, clear, and inspect cache statistics via CLI
- Helper Functions — Convenient global helpers for quick access
- Facade Support —
ModelCachefacade for dependency injection - Dynamic Magic Methods — Call
findStores($id),allStores(), etc. directly - Fallback to Database — Gracefully falls back to database queries when cache is empty
Requirements
- PHP 8.4+
- Laravel 12+
Installation
The package is located at Lotestudio/ModelCache and is auto-discovered via Laravel's service provider registration.
Service Provider
Register the service provider in bootstrap/providers.php (Laravel 12) or config/app.php:
Facade (Optional)
Add to the aliases array in config/app.php:
Configuration
Publish the configuration file:
Model Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
model |
string |
required | Full class name of the Eloquent model |
key |
string |
required | Unique cache key identifier |
ttl |
int |
86400 |
Cache TTL in seconds |
order_by |
string |
— | Column to order results by |
order_direction |
string |
'asc' |
Sort direction (asc or desc) |
fields |
array |
null (all) |
Specific columns to select |
conditions |
array |
[] |
Where clauses [['column', 'operator', value], ...] |
Usage
Basic Usage
Dynamic Magic Methods
The __call magic method provides convenient shortcuts:
Helper Functions
Using the Interface (Dependency Injection)
Artisan Commands
Warm Up Cache
Clear Cache
Cache Statistics
Observer-Based Auto-Clear
When auto_clear is enabled in the config, the package automatically registers model observers that clear the relevant cache whenever a model is saved, updated, deleted, or restored.
The service provider checks for a custom observer at App\Observers\{ModelName}Observer before falling back to the generic ModelCacheObserver.
Architecture
Cache Invalidation
Cache is automatically invalidated via model observers when:
saved— Model is created or updatedupdated— Model is updateddeleted— Model is deletedrestored— Model is restored from soft delete
Manual invalidation is also available via clear() or the Artisan command.
License
This is internal application code. All rights reserved.