mikebronner / laravel-model-caching

Eloquent model-caching made easy.
MIT License
2.25k stars 212 forks source link

Can it support row-level caching? #306

Closed ShyZhen closed 4 years ago

ShyZhen commented 4 years ago

Hello, i'm a novice at laravel, i have a question, can it support row-level caching?

Because I see that whether you delete or update a piece of data, the entire library will be flushed, i want to delete or update only the current record when i delete or update a record. Is there any way to achieve this scenario?

Thank a lot.

Environment

mikebronner commented 4 years ago

Hi @ShyZhen, it depends on your cache store type (array, file, redis, memcached, etc). If you use a cache store that does not support tags, it will always flush the entire cache. If you use a cache store that does support tags, it will only flush the models that are affected in that category. Row-level, or specific model instance flushing is not supported due to the technical complexity involved. This isn't something I would consider implementing at this time, unless someone submitted this as a PR and performance was not degraded.

dhcmega commented 4 years ago

Hi! If the cache is flushed when using a cache that does not support tags, will it still make sense? Will the cache only be used if the same query runs more than once during any given execution?

For memcached to work, will this setup be enough? I don't have igbinary, json and msgpack? At the moment, I only have "file", "database" or this "memcached":

Version | 3.0.4
libmemcached version | 1.0.8
SASL support | no
Session support | yes
igbinary support | no
json support | no
msgpack support | no

Thanks!

mikebronner commented 4 years ago

Hi @dhcmega, thanks for writing in!

If you use a cache that doesn't use tags, it will clear the entire cache every time something changes. It is not really meant for that type of operation, and you're probably better off not using this package.

in your case memcached would be the preference.

dhcmega commented 4 years ago

Hi @mikebronner, thank you very much for responding. I'm testing it right now with memcached and every thing seems good. Will keep on dev for a few days. Is ext-memcached actually needed? Thanks!

mikebronner commented 4 years ago

I'm not sure, as I have always been using redis. My recommendation would be to follow the Laravel guidelines on installing Memcached: https://laravel.com/docs/7.x/cache#driver-prerequisites