laravel-repositories icon indicating copy to clipboard operation
laravel-repositories copied to clipboard

Caching

Open Jamesking56 opened this issue 5 years ago • 2 comments

It would be great if this package provided a new abstractclass called CachedRepository which would cache repository responses for better performance (and add an API to clear said caches).

Jamesking56 avatar Nov 03 '18 16:11 Jamesking56

@Jamesking56 interesting. In the past I've done this by having an abstract parent repository that does something like:

public function getOrSet(\Closure $functionality, ...$arguments) {
    $hash = generateHashFromArgumentsAndStuff();
    $result = $this->cache->get($hash);

    if (! $result) {
        $result = $functionality(...$arguments);
        $this->cache->set($has, $result);
    }

    return $result;
}

I've even experimented with the idea of using the backtrace to get the method name and generate a custom hash. What would you expect? Auto keys or specified?

ollieread avatar Nov 05 '18 17:11 ollieread

I'd actually like to see auto keys with the option of specify custom ones

Jamesking56 avatar Nov 05 '18 17:11 Jamesking56