Giter Club home page Giter Club logo

Comments (9)

Ocramius avatar Ocramius commented on June 27, 2024 2

Tricky. I think that setting a default TTL (default null) is a good idea here, as data fetched and kept "hot" is not necessarily always fresh.

Thoughts @doctrine/doctrinecore?

from cache.

holtkamp avatar holtkamp commented on June 27, 2024 1

mmm, just encountered this issue and it is actually quite "severe" right? It might also explain some crazy behaviour I have encountered for which I usually resorted to using a "TTL-specific" cacheEntryIdentifier...

Description
Mainly for my own understanding, a short description with an example.

Imagine an application running somewhere in the cloud, which typically reboots once every 24 hours with the following ChainCache:

  • fast and volatile: is cleared on each server restart
  • slow and persistant

Now suppose :

  • a cache entry X is saved to the ChainCache with a TTL of 4 hours
    • cache entry X is saved to the fast cache with a TTL of 4 hours
    • cache entry X to the slow cache with a TTL of 4 hours
  • the server is restarted, clearing the fast and volatile cache (APCu)
  • cache entry X is looked up
    • cache entry X is not found in the fast (APCu) cache
    • cache entry X is found in the slow cache
    • cache entry X will be propagated to / stored in the fast cache with infinite TTL
  • after 4 hours, cache entry X is looked up again
    • cache entry X is found in the fast (APCu) cache and used, potentially leading to strange behavior
  • ... repeat, repeat, repeat using invalid cache entry until next server restart

Possible solutions
As suggested here #246 (comment), the second proposal of trying to determine the remaining TTL would be the most elegant, but quite challenging to implement for all various CacheProviders. Maybe we can check whether a CacheProvider implements a specific interface like:

interface RemainingTimeToLiveAwareCacheProvider
{
	public function getRemainingTimeToLiveInSeconds(string $cacheEntry): int
}

In case a CacheProvider does not implement such interface, we can fall back to solution number 1: allow to define a default TTL for the ChainCache, which defaults to null, but can be set to a relative short periods to prevent problems / strange behaviour, but does increase the load on the slow cache...

Approach
A viable approach might be to first start with the default TTL which can be set upon ChainCache initialization. And THEN come up with the interface?

Note that Symfony can be used as inspiration, it uses:

from cache.

malarzm avatar malarzm commented on June 27, 2024 1

I'll try to backport your fix to 1.10.x branch and cut a new release this evening :)

from cache.

lchenay avatar lchenay commented on June 27, 2024

For proposal 2, many backend don't have a getter to retrieve the remain ttl.
A quick solution could be to wrap the cachedData in an object containing the {cachedData, ttl}.
But it will prevent to reuse the same Cache server without instancing a ChainCache as the stored data is not in the same format.

Without a new elegant solution on proposal 2, not sure it's worth it.

from cache.

holtkamp avatar holtkamp commented on June 27, 2024

Anyone got feedback on the suggested approach?

from cache.

holtkamp avatar holtkamp commented on June 27, 2024

@Ocramius this issue:

from cache.

malarzm avatar malarzm commented on June 27, 2024

Thanks for the heads up!

from cache.

holtkamp avatar holtkamp commented on June 27, 2024

@malarzm sorry, I misread this page:

1.10.1...master

1.10.1 was tagged on 27-05-2020 and #335 was merged one day later 28-05-2020, so it was not included in 1.10.1

So I think this issue needs to be re-opened until new release is tagged? Probably a patch version 1.10.2 suffices?

from cache.

holtkamp avatar holtkamp commented on June 27, 2024

@beberlei can you have a look at this? Been trying to solve quite a serious bug since #246 (comment), only think remaining is tagging it in a new release...

from cache.

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.