Comments (11)
@andreshg112 See https://github.com/GeneaLabs/laravel-model-caching#experimental-cache-cool-down-in-specific-models. It let's you turn off cache invalidation for a certain time an extremely high-traffic models that aren't critical. For example, you may not want to invalidate cache every time a comment is added, but instead only invalidate that cache every 15 minutes. This could cause comments to only appear to update every 15 minutes on the website, depending on how you decide to implement that feature.
I actually never use cache cool down. It was a feature request some time back.
from laravel-model-caching.
If everything works as expected you do not need TTL.
After you change some data on the model itself or on the related models the cache will be devalidated automatically.
from laravel-model-caching.
@borovaka We have some legacy code base which does not use Eloquent and Laravel at all, that's why we need TTL.
from laravel-model-caching.
How do you think to use this package then? It is binding to the eloquent methods and properties. Are you planning to mock this methods in your legacy code?
If this is the case, you can create rememberForever method on your current entities base class and implement TTL there.
from laravel-model-caching.
@Eke Thanks for inquiring about this. @borovaka is correct, this package is intended for Laravel use specifically. It can't really be used without Eloquent.
from laravel-model-caching.
This would be great in my case because I have a database that is filling so fast, so I want to add a TTL in order to free space because I have to do it manually. I cannot configure a cron job right now.
from laravel-model-caching.
@andreshg112 Could you elaborate? If configured correctly, Redis or MemCached should be managing their storage automatically, and invalidating their cache when they run out of space.
Or are you talking about you need to cull your actual database manually from time-to-time of old records, and when you do that, the cache is no longer in sync with the database?
from laravel-model-caching.
Thanks for answering! The cache is always synced with the database. Even, we do not modify the database frequently. However, when the Redis server is full, this package cannot write to the server anymore, so we get this error:
RedisException: OOM command not allowed when used memory > 'maxmemory'.
#58 vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(96): sAdd
#57 vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(96): command
#56 vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(108): __call
#55 vendor/laravel/framework/src/Illuminate/Redis/Connections/PhpRedisConnection.php(410): __call
#54 vendor/laravel/framework/src/Illuminate/Cache/RedisTaggedCache.php(127): pushKeys
#53 vendor/laravel/framework/src/Illuminate/Cache/RedisTaggedCache.php(111): pushForeverKeys
#52 vendor/laravel/framework/src/Illuminate/Cache/RedisTaggedCache.php(72): forever
#51 vendor/laravel/framework/src/Illuminate/Cache/Repository.php(362): rememberForever
#50 vendor/genealabs/laravel-model-caching/src/CachedBuilder.php(288): retrieveCachedValue
#49 vendor/genealabs/laravel-model-caching/src/CachedBuilder.php(233): cachedValue
#48 vendor/genealabs/laravel-model-caching/src/CachedBuilder.php(96): get
#47 app/Http/Controllers/BestAlternativesController.php(492): getRoutesByStationIds
#46 app/Http/Controllers/BestAlternativesController.php(192): directCalculation
#45 app/Http/Controllers/BestAlternativesController.php(73): __invoke
#44 app/Http/Controllers/BestAlternativesController.php(0): call_user_func_array
#43 vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): callAction
#42 vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): dispatch
#41 vendor/laravel/framework/src/Illuminate/Routing/Route.php(212): runController
#40 vendor/laravel/framework/src/Illuminate/Routing/Route.php(169): run
#39 vendor/laravel/framework/src/Illuminate/Routing/Router.php(665): Illuminate\Routing\{closure}
#38 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Routing\{closure}
#37 app/Http/Middleware/SaveQuery.php(26): handle
#36 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\{closure}
#35 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\{closure}
#34 vendor/barryvdh/laravel-cors/src/HandleCors.php(36): handle
#33 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\{closure}
#32 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\{closure}
#31 vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): handle
#30 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\{closure}
#29 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\{closure}
#28 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): then
#27 vendor/laravel/framework/src/Illuminate/Routing/Router.php(667): runRouteWithinStack
#26 vendor/laravel/framework/src/Illuminate/Routing/Router.php(642): runRoute
#25 vendor/laravel/framework/src/Illuminate/Routing/Router.php(608): dispatchToRoute
#24 vendor/laravel/framework/src/Illuminate/Routing/Router.php(597): dispatch
#23 vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\Foundation\Http\{closure}
#22 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Routing\{closure}
#21 vendor/fideloper/proxy/src/TrustProxies.php(57): handle
#20 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\{closure}
#19 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\{closure}
#18 vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(31): handle
#17 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\{closure}
#16 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\{closure}
#15 vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(31): handle
#14 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\{closure}
#13 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\{closure}
#12 vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): handle
#11 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\{closure}
#10 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\{closure}
#9 vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(62): handle
#8 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\{closure}
#7 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\{closure}
#6 vendor/barryvdh/laravel-cors/src/HandlePreflight.php(29): handle
#5 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\{closure}
#4 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\{closure}
#3 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): then
#2 vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): sendRequestThroughRouter
#1 vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): handle
#0 public/index.php(55): null
From this midnight to this midday (12 hours), it has occupied 5.1 GB. The day the application was released, it occupied 20 GB in a few hours. That's the reason why I want to set a TTL.
The graphic below shows the max space occupied in bytes in the Redis instance in the last week in a period of six hours.
from laravel-model-caching.
@andreshg112 Thanks for the detailed response! Let's see if we can't get your Redis server to dump cache when it runs out of space. Have you taken a look at this article: https://ma.ttias.be/redis-oom-command-not-allowed-used-memory-maxmemory/
specifically solution 2? Let me know if that doesn't work for you.
Also take a look at this article: https://aws.amazon.com/premiumsupport/knowledge-center/oom-command-not-allowed-redis/
Specifically the settings around making space by evicting the least-accessed keys.
Let me know how that goes.
from laravel-model-caching.
I'm checking it. Thanks!
Got a question. I don't know what "cache cooldown" is. I see it a lot in the code.
from laravel-model-caching.
@andreshg112 Thanks for the detailed response! Let's see if we can't get your Redis server to dump cache when it runs out of space. Have you taken a look at this article: https://ma.ttias.be/redis-oom-command-not-allowed-used-memory-maxmemory/
specifically solution 2? Let me know if that doesn't work for you.Also take a look at this article: https://aws.amazon.com/premiumsupport/knowledge-center/oom-command-not-allowed-redis/
Specifically the settings around making space by evicting the least-accessed keys.Let me know how that goes.
I think this is gonna work. I tried it in a testing environment and everything is ok. I'll answer here if it works as expected in production.
Thank you so much!
from laravel-model-caching.
Related Issues (20)
- What is cacheCooldownSecounds definition? HOT 1
- Add support for Laravel 10 HOT 2
- Object of class Illuminate\\Database\\Query\\Expression could not be converted to string HOT 6
- Since 0.12.4 I get error "GeneaLabs\LaravelModelCaching\CacheKey::processEnum(): Argument #1 ($value) must be of type BackedEnum|UnitEnum|string, null given, called in ...\vendor\genealabs\laravel-model-caching\src\CacheKey.php on line 409" HOT 25
- Cannot access "parent" when current class scope has no parent HOT 1
- Laravel v10.3.0 breaks LaravelModelCaching HOT 2
- checkCooldownAndFlushAfterPersisting(): Argument #2 ($relationship) must be of type string, array given, called in /var/www/html/vendor/genealabs/laravel-model-caching/src/Traits/ModelCaching.php on line 83 HOT 8
- Is table join supported? HOT 7
- The attribute [column3] either does not exist or was not retrieved for model HOT 1
- Stale cached value returned where(...)->first() HOT 4
- Fix for GeneaLabs\LaravelModelCaching\CacheKey::processEnum(): Argument #1 ($value) must be of type BackedEnum|UnitEnum|string, null given
- processEnum(): Argument #1 ($value) must be of type BackedEnum|UnitEnum|Illuminate\Database\Query\Expression|string, null given HOT 2
- Conflict with Spatie Schemaless
- Laravel 11 upgrade blocked by laravel-pivot-events dependency HOT 1
- Missing import in CachedBuilder?
- Fix failing tests HOT 1
- Uuid fromBytes throwing a error HOT 1
- Observer for Pivot Model not firing HOT 3
- Bug: CacheKey::getValuesFromBindings(): Return value must be of type string, null returned | when where value is null HOT 1
- Object of class Illuminate\Database\Query\Expression could not be converted to string
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-model-caching.