railken/cacheable

24,771
Install
composer require railken/cacheable
Latest Version:v0.2.0
PHP:>=8.1
Laravel:9 · 10
License:MIT
Last Updated:Mar 27, 2024
Links: GitHub  ·  Packagist
Maintainer: railken

Cacheable

Actions Status

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 by typing the following command:

composer require railken/cacheable

Usage

Add the CacheableTrait and CacheableContract in the class you wish to cache

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

$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

Related Packages

valeryq/cacheable

Laravel Cacheable

101 5
karriere/state

Laravel package for storing current application state in cache/session

19,819 17
yateric/cacheable

Makes any object method return cacheable.

10 1
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

641,106,524 9,700
laravel/framework

The Laravel Framework.

593,882,149 34,959

Version History

Version Released PHP Laravel License
v0.2.0 >=8.1 9.* | 10.* MIT
v0.1.5 >=7.1 5.*|6.*|7.*|8.* MIT
v0.1.4 >=7.1 5.* || 6.* || 7.* MIT
v0.1.3 >=7.1 5.* MIT
v0.1.2 >=7.1 5.* MIT