🎇Implementing cache for other functions than get()
Since all of the Laravel Eloquent functions are based on it, the builder that comes with this package replaces only the get()
one:
In case that you want to cache your own methods from your custom builder or, for instance, your count()
method doesn't rely on get()
, you can replace it using this syntax:
In fact, you can also replace any eloquent method within your builder if you use $this->shouldAvoidCache()
check and retrieve the cached data using getFromQueryCache()
method, passing the method name as string, and, optionally, an array of columns that defaults to ['*']
.
Notice that the getFromQueryCache()
method accepts a method name and a $columns
parameter. If your method doesn't implement the $columns
, don't pass it.
Note that some functions, like getQueryCacheCallback()
may come with an $id
parameter. The default behavior of the package doesn't use it, since the query builder uses ->get()
by default that accepts only columns.
However, if your builder replaces functions like find()
, $id
is needed and you will also have to replace the getQueryCacheCallback()
like so:
Last updated