Closed mikebronner closed 2 years ago
@tuseroni Let's continue the discussion here.
i did find a workaround, might help anyone else having this problem, least til it's resolved: call $obj->flushCache() when saving, or override save on the model (or in my case "cacheableClass" which implements the caching on all models) to look kinda like the following:
use Cachable;
public function save(array $options = [])
{
parent::save($options);
$this->flushCache();
}
if i call this the list shows up correctly, i don't know enough about how laravel handles caching, or how you are implementing caching to know what causes this, i'm looking over your code at the moment to see if i can spot (which was how i found the flushCache command which worked as a workaround so i didn't have to disable cache on the listing)
i'll tell you if i see something that stands out.
@tuseroni Sorry I didn't see this until now: if you are using this package, don't use any other caching packages. watson/rememberable
is likely conflicting. Closing this for now. Let me know if that fixes it.
i'm not using watson/rememberable, i used it at one point which is why it's in my requires but the class doesn't implement it
@tuseroni Hmm, I'm not seeing anything that would cause this from what you describe above. Can you provide a public repo that reproduces the problem that I can test with?
i'll see what i can do, but i don't own the code i'm working with so i will have to find a way to reproduce it myself.
I think I'm having this issue. I'm syncing some ids for my pivot table. When cache enabled, I can't see some relationship query results. Bu when disabled cache I can see results.
I can confirm the same issues here. I have had to disable it on several models because of this.
@reasecret @Jafo232 Can you please provide your specific Eloquent queries, as well as the version of laravel-model-caching package you have installed, along with the version of Laravel. If at all possible, would love a PR with a failing test so I can figure out how to reproduce this.
@mikebronner Here's an example of it, since I also ran into the issue.
$company->tags()->sync($request->tags);
The "sync" method does not seem to invalidate the cache. Once the cache is manually flushed, all is good again.
Company is not cacheable, but tags model is. Company model
public function tags()
{
return $this->belongsToMany(Tag::class)->withTimestamps();
}
Tags model
public function companies()
{
return $this->belongsToMany(Company::class);
}
@LiamAird Thanks for the further clarification on this. I will look into it.
Seems like we have this problem too. The sync() function is not working anymore. Saving relations with sync() is not working when we've enabled use Cachable;
What just @Bjornftw said.
@mikebronner I sent a PR fixing this (#433), I don't know the relation with this specific issue tho
This is fixed in v0.12.5
Closing this for as it was fixed in #433
i'm having this issue as well, least i think they are related. i have the following model:
syncableBase overrides hasMany but not belongsTo and uses cacheable.
if i save an existing object (one acquired via get) there is no problems, if i save a new object without any relationships, no problems, the only problem is when i create a new object, save, sync the ids, and then save again (i don't think the separate saves are part of the issue, but if i don't do the first save it never does the sync, because there is no id for the product)
it seems the save should invalidate the cache, and given there were two saves that should doubly so
relevant part of that:
so after doing this, i go to a list of products as follows:
and the product i just created isn't in the list, if i clear the cache it shows up, if i save the product i just created again (from the product edit screen) the product will show in the list also, don't let that limit bother you, you there are only 4 products in the database right now.
it's quite perplexing.
i don't THINK i'm using nova, here are my requires:
so my problem MIGHT not be related to his or both of our problems may be unrelated to nova.
Originally posted by @tuseroni in https://github.com/GeneaLabs/laravel-model-caching/issues/278#issuecomment-520457213