Giter Club home page Giter Club logo

Comments (2)

bitfaster avatar bitfaster commented on May 29, 2024

To set some context, LRU caches at most n items, and keeps them in memory as long as possible in order to maximize the chance of a cache hit. In other words, budget some fixed amount of memory for caching and try to maximize efficiency. TLRU is the same, but items have an explicit TTL and can therefore age out. So, expiry is only really applicable to TLRU.

I had considered adding a Trim method similar to MemoryCache.Trim(int percent) that could be hooked up to a background thread or some other event in the program like inactivity or memory pressure. It would work slightly differently for each cache:

  • LRU.Trim(int itemCount) trim the n least recently used items.
  • TLRU.Trim(int itemCount) trim all e=expired items, then the remaining n-e least recently used items, if any.

TLRU.Expire() would then be implemented as TLRU.Trim(0) to remove only expired items. You would then be able to explicitly choose whether to spin up a thread or hook into some other existing process, and how aggressively to trim.

The main reason Trim() doesn't exist is because I have never needed it in practice. Do you have a situation in mind where this is a deal breaker and LRU eviction doesn't work?

from bitfaster.caching.

alex-jitbit avatar alex-jitbit commented on May 29, 2024

Do you have a situation in mind where this is a deal breaker

I'm just looking for a complete replacement for MemoryCache which is slower than yours

from bitfaster.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.