Looking to hire Laravel developers? Try LaraJobs

laravel-cache-helper maintained by d076

Description
Small helper for Laravel Cache facade
Author
Last update
2023/11/06 15:07 (dev-main)
License
Links
Downloads
6

Comments
comments powered by Disqus

laravel-cache-helper

Small helper for Laravel Cache facade

Quick Setup

composer require d076/laravel-cache-helper

Usage

Add HasCached trait to your class which methods you want to cache.

use D076\LaravelCacheHelper\Traits\HasCached;

class SomeClass
{
    use HasCached;
    
    public function someMethod($params)
    {
        ...
    }
    
    public static function someStaticMethod($params)
    {
        ...
    }
}

Important

Your class or parent classes/traits should not contain override __call and __callStatic methods. So you can`t use HasCached trait in your Models.

Now you can call your methods with Cached or ForceCached prefix.

Optionally, you can pass last parameter $ttl in seconds.

$someClass->someMethodCached($params, $ttl);
$someClass->someMethodForceCached($params, $ttl);

SomeClass::someStaticMethodCached($params, $ttl);
SomeClass::someStaticMethodForceCached($params, $ttl);