mikebronner / laravel-model-caching

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

Cache Expire (no forever cache) #243

Closed ktanakaj closed 5 years ago

ktanakaj commented 5 years ago

Is your feature request related to a problem? Please describe. I use redis memory cache store. I don't have large memory. But I guess laravel-model-caching reserve memory for a long term because it use Cache::rememberForever only.

Describe the solution you'd like I want to set cache expire to remove inactive records.

The expire may be configured like the following. config(['laravel-model-caching.cache-prefix' => 'test-prefix']); protected $cacheCooldownSeconds = 300;

Describe alternatives you've considered I overrode CachedBuilder and replaced rememberForever to remember like this.

mikebronner commented 5 years ago

@ktanakaj This shouldn't be necessary, as Redis and MemCached will remove old cache entries automatically when it needs more space. If that is not the case, please let me know.

Proper Redis configuration is essential to make this work correctly: https://stackoverflow.com/questions/5068518/what-does-redis-do-when-it-runs-out-of-memory

Take a closer look at the max memory and eviction policy settings.

mikebronner commented 5 years ago

Closing issue for now, please re-open if you don't see redis behaving as expected.

ktanakaj commented 5 years ago

Thanks. But I can't change max memory policy because my redis has not cache only. There are session data and user temporary data too... I will use my custom CachedBuilder.

mikebronner commented 5 years ago

@ktanakaj That shouldn't really matter. Redis will still purge stale records if it needs more cache space. With proper configuration Redis can be set up to utilize virtual memory (storing stale records off to disk, instead of purging) in conjunction with memory limits.