Cache - SQLite based cache driver with some fancy extras like tagging and encryption etc.
The Cache package an SQLite based cache driver with some fancy extras like tagging and encryption.
- Matt Lantz (@mattylantz, mattlantz at gmail dot com)
- PHP 8.2+
| Laravel Version | Package Tag | Supported |
|---|---|---|
| ^11.x | 1.x | yes |
| ^12.x | 1.x | yes |
| ^13.x | 1.x | yes |
Start a new Laravel project:
composer create-project laravel/laravel your-project-nameThen run the following to add Support
composer require "grafite/cache"Append to the cache.php config file in the stores array:
'sqlite' => [
'driver' => 'sqlite',
'table' => 'cache',
'database' => env('CACHE_DATABASE', database_path('cache.sqlite')),
'prefix' => '',
'encrypted' => false,
// Concurrency settings (these are the defaults, omit them to keep them)
'busy_timeout' => 10000,
'journal_mode' => 'wal',
'synchronous' => 'normal',
'transaction_mode' => 'IMMEDIATE',
],The cache connection ships with settings that let several processes (queue workers, Horizon, web requests) share one SQLite file without database is locked errors:
| Key | Default | What it does |
|---|---|---|
busy_timeout |
10000 |
Milliseconds a connection waits for a lock before failing. |
journal_mode |
wal |
Write-ahead logging: readers don't block the writer and the writer doesn't block readers. |
synchronous |
normal |
Safe with WAL and much faster than full. |
transaction_mode |
IMMEDIATE |
Takes the write lock at the start of increment/decrement (used by rate limiters), so contending workers wait their turn instead of failing. Accepts DEFERRED, IMMEDIATE or EXCLUSIVE. |
Set any of these to null to leave SQLite's own default in place. transaction_mode is applied on every supported Laravel and PHP version. Laravel 12+ on PHP 8.4+ handles it natively, and the package handles it everywhere else.
WAL notes:
- SQLite creates
cache.sqlite-walandcache.sqlite-shmnext to the database. The directory must be writable by every user that runs a worker. If you delete the cache database by hand, delete those two files too. - WAL does not work on network filesystems (NFS, SMB). Keep the cache file on local disk.
If your queue also uses SQLite (QUEUE_CONNECTION=database with an SQLite connection), that connection belongs to your app, not this package. Add the same keys to database.connections.sqlite in config/database.php. Laravel only honours transaction_mode there on Laravel 12+ with PHP 8.4+.
https://documentation.grafite.ca/docs/utilities-cache
Support is open-sourced software licensed under the MIT license
Please add as many details as possible regarding submission of issues and feature requests
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
