https://github.com/railken/cacheable
https://github.com/railken/cacheable
cache cacheable laravel methods trait
Last synced: 23 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/railken/cacheable
- Owner: railken
- License: mit
- Created: 2019-05-02T22:26:15.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-03-27T18:51:39.000Z (about 2 years ago)
- Last Synced: 2025-02-24T21:46:27.498Z (over 1 year ago)
- Topics: cache, cacheable, laravel, methods, trait
- Language: PHP
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cacheable
[](https://github.com/railken/cacheable/actions)
This library give you the ability to call any method with a suffix `Cached` to retrieve a Cached result of the methods. This comes in handy when you have a really time consuming method and the result is always be the same given the same parameters
# Requirements
- PHP 8.1 and later
- Laravel
## Installation
You can install it via [Composer](https://getcomposer.org/) by typing the following command:
```bash
composer require railken/cacheable
```
## Usage
Add the `CacheableTrait` and `CacheableContract` in the class you wish to cache
```php
use Railken\Cacheable\CacheableTrait;
use Railken\Cacheable\CacheableContract;
class Foo implements CacheableContract
{
use CacheableTrait;
public function sum(int $x, int $y): int
{
return $x + $y;
}
public function random(): string
{
return str_random(10);
}
}
```
Now you can play with the method
```php
$foo = new Foo();
$foo->sumCached(2, 8); // 10
$foo->randomCached(); // Return always the same string
```
In order to cleanup the cache simply run `php artisan cache:clean`