ferdiunal / laravel-cache-couchdb
This package provides a cache store implementation for Laravel that uses a CouchDB database to store cached items. It supports both the default and tagged cache functionality of Laravel.
Requires
- php: ^8.1|^8.2
- doctrine/couchdb: ^1.0@beta
- illuminate/contracts: ^9.0|^10.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-11-09 03:57:05 UTC
README
This package provides a cache store implementation for Laravel that uses a CouchDB database to store cached items. It supports both the default and tagged cache functionality of Laravel.
Requirements
This package requires the following:
- PHP >= 8.2
- Laravel >= 9.0
- A CouchDB instance
Installation
You can install this package via Composer. Run the following command:
composer require ferdiunal/laravel-couchdb-cache
Configuration
To use the CouchDB cache driver, you will need to add it to the config/cache.php
file as follows:
'default' => env('CACHE_DRIVER', 'file'), ... 'couchdb' => [ 'driver' => 'couchdb', 'host' => env('COUCHDB_HOST', 'localhost'), 'port' => env('COUCHDB_PORT', 5984), 'user' => env('COUCHDB_USERNAME', null), 'password' => env('COUCHDB_PASSWORD', null), 'ip' => env('COUCHDB_IP', null), 'ssl' => env('COUCHDB_SSL', false), 'path' => env('COUCHDB_PATH', null), 'logging' => env('COUCHDB_LOGGING', false), 'timeout' => env('COUCHDB_TIMEOUT', 0.01), 'dbname' => env('COUCHDB_DATABASE', 'your_database_name'), 'prefix' => env('CACHE_PREFIX', 'your_cache_prefix'), ];
You can then set the CACHE_DRIVER
environment variable to 'couchdb'
to use the CouchDB cache driver.
Usage
After the configuration is set up, you can use the CouchDB cache driver in your Laravel application as you would any other cache driver. Here are a few examples:
// Store an item in the cache for 10 minutes Cache::put('key', 'value', 10); // Retrieve an item from the cache by key $value = Cache::get('key'); // Retrieve multiple items from the cache by keys $values = Cache::many(['key1', 'key2']); // Increment the value of an item in the cache Cache::increment('key'); // Decrement the value of an item in the cache Cache::decrement('key'); // Remove an item from the cache Cache::forget('key'); // Remove all items from the cache Cache::flush();
Tagged Cache
The CouchDB cache driver also supports the tagged cache functionality of Laravel. Here are a few examples:
// Store an item in the cache with a tag Cache::tags(['tag1', 'tag2'])->put('key', 'value', 10); // Retrieve all items with a tag Cache::tags('tag1')->get('key'); // Remove all items with a tag Cache::tags('tag1')->flush();
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.