Giter Club home page Giter Club logo

Comments (2)

mreiche avatar mreiche commented on June 29, 2024

Fact is, the CacheService doesn't invalidate the outdated keys by its own, that is right. The documentation should be more clear here that you should implement your "garbage collector" on your own like that.

window.setInterval(() => {
    this._cacheService.invalidate(this._cacheService.outdatedKeys);
}, 10000);
  1. What we actually want to cache is values, not keys. We should TTL the values, not the keys. Only when the key is written to should TTL start counting down for it.

I dont know what you mean. This is a key-value-store where you only can TTL the key.

  1. When a key times out before the value is written, discard the write (and emit a warning, I guess): This cache is not properly configured to handle the response times encountered, so they will never be cached.

A write always refreshes the key TTL.
There is only one real issue for a race condition, when the loading callback takes too long.

this._cacheContainer[key] = [
    now,
    loadingFunction().then(object=>{
        return this._cacheContainer[key][1] = Promise.resolve(object);
    })
];

when the loadingFunction() takes more than the cacheTtlSeconds, the key could be deleted in the meantime and this._cacheContainer[key] became undefined. In this case, the better option should be to write:

this._cacheContainer[key] = [
    now,
    loadingFunction().then(object=>{
        const now = (Date.now()/1000);
        return this._cacheContainer[key] = [now, Promise.resolve(object)];
    })
];

That should fix it.

Opinions?

We should have tests for that.

from aurelia-components.

Zsar avatar Zsar commented on June 29, 2024

Mmh. Maybe I should demonstrate... created #42 .
... If the TTL is lower than the time to answer, then TTL-ing the key will result in never receiving it. So I figure, maybe we'd better TTL the value.

from aurelia-components.

Related Issues (16)

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.