Giter Club home page Giter Club logo

Comments (11)

mikebronner avatar mikebronner commented on July 29, 2024 1

@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.

borovaka avatar borovaka commented on July 29, 2024

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.

Eke avatar Eke commented on July 29, 2024

@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.

borovaka avatar borovaka commented on July 29, 2024

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.

mikebronner avatar mikebronner commented on July 29, 2024

@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.

andreshg112 avatar andreshg112 commented on July 29, 2024

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.

mikebronner avatar mikebronner commented on July 29, 2024

@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.

andreshg112 avatar andreshg112 commented on July 29, 2024

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.
imagen

from laravel-model-caching.

mikebronner avatar mikebronner commented on July 29, 2024

@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.

andreshg112 avatar andreshg112 commented on July 29, 2024

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 avatar andreshg112 commented on July 29, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.