mikebronner / laravel-model-caching

Eloquent model-caching made easy.
MIT License
2.26k stars 215 forks source link

Work with 'whereIn' queries as with multiple 'where' queries #411

Closed msnegurski closed 2 years ago

msnegurski commented 2 years ago

First of all, thank you for such an awesome package.

Is your feature request related to a problem? Please describe. In an app I am developing there are lots of whereIn queries. This package caches them with ..._in_... keys. So for example, if I take three models by IDs Model::whereIn('id', [1, 2, 3]), query will be cached with key ...id_in_1_2_3.... However, if I then query only first two models Model::whereIn('id', [1, 2]), it will look for cache with key ...id_in_1_2..., will not find it, and create separate entry, even though first two models are already loaded in cache and technically could be used.

Describe the solution you'd like Would be cool if there was an option for some Models to separate their cache for whereIn queries into separate single where cache keys, if that makes sense? So that in example above cache for the first query would be written as three separate cache entries with keys ...id=1... ...id=2... ...id=3.... And so after second query is made, it will look for two cache entries with keys ...id=1... ...id=2... and hit both of them.

mikebronner commented 2 years ago

Hi @msnegurski, thanks for writing in! I do understand where you are coming from, but this package only caches eloquent query results, not the models themselves. Unfortunately the functionality you are describing is the caching of models, which means it won't be something we will be attempting to address at this time.