New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to renew or reset when using Eloquent cache? #2794
Comments
You mean without doing |
@Anahkiasen, yes. without using |
Didn't I tell this on irc a while ago? $query = Countries::newQuery()->remember(5);
Cache::forget($query->getCacheKey());
$countries = $query->get(); |
@anlutro wouldn't it be nice to have p/s: Not entirely agree with the method name. |
@anlutro, Don't seem to have noticed it on IRC. I will try to check the messages again. Thnx for notifying again. Appreciate your help. @crynobone, I was thinking on the same terms as well |
Or maybe just the option to do |
IMO |
I don't think |
Maybe in 4.1 cached queries can be tagged with |
Model::whereUserId(5)->remember()->get();
// and
Model::whereId(5)->remember()->get(); should both generate two different key, if we tagged it with just |
@crynobone: Yeah thats the idea ;) There could be 2 options to have a little something something for everyone: First: |
Using the cache key attribute can be helpful : // get last 5 users
$users = User::remember(60, 'last_5_users')->orderBy('created_at', 'desc')->take(5)->get();
// delete this specific cache entry
Cache::forget('last_5_users'); |
Yes, I would just pass a cache key as noted by @semalead. |
@taylorotwell, @semalead, could you advice on how should the implementation be in case of the below scenario: Countries Table
So calling
will retrieve all countries starting with the letter Is there a way to clear all cache that belong to the model |
Discussed with @taylorotwell over IRC, and we can use the tags method of the query builder to do this.
And you can use the
Thnx @taylorotwell. Laravel is super cool... |
Reading the documentation of Laravel 4.2 it seems that the correct way of implementing the tagging is to write the following:
Note the So that the flushing of tags will work:
And it is worth noting that you have to use the I'm just starting to look into this, having some issues. But it's an promising solution... @taylorotwell @abishekrsrikaanth My issue now is that Edit: Both In short, the approach works great, if implemented correctly... ;) |
If I am caching the results of a Eloquent object using
or
how can i renew or reset this to fill in fresh data from the database to the cache?
The text was updated successfully, but these errors were encountered: