laravel-repositories
laravel-repositories copied to clipboard
Caching
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 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?
I'd actually like to see auto keys with the option of specify custom ones