Giter Club home page Giter Club logo

Comments (4)

janisz avatar janisz commented on May 27, 2024 1

So why wasn't a method considered to allow setting expiration time for each cache key?

While it is technically feasible to implement such a feature, it could introduce complexity to the cache system. The bigcache library is based on a circular buffer (i.e., queue.BytesQueue) and does not have a defragmentation process. If we allow every key to be removed at different times, it could result in a significant amount of unused memory. On the other hand, we do allow the removal of a single key, but it is more like marking it as obsolete rather than actually deleting it.

from bigcache.

zsyu9779 avatar zsyu9779 commented on May 27, 2024 1

So why wasn't a method considered to allow setting expiration time for each cache key?

While it is technically feasible to implement such a feature, it could introduce complexity to the cache system. The bigcache library is based on a circular buffer (i.e., queue.BytesQueue) and does not have a defragmentation process. If we allow every key to be removed at different times, it could result in a significant amount of unused memory. On the other hand, we do allow the removal of a single key, but it is more like marking it as obsolete rather than actually deleting it.

Regarding the problem of memory waste, can we consider designing a compression algorithm? That is, when operating the bytesQueue, record the number of expired keys, and when the number of expired keys reaches a certain threshold, start a compression algorithm to asynchronously create a new, expanded bytesQueue. Then move the data from the old bytesQueue to the new one. During this process, read and write requests are synchronized between the two bytesQueues.

from bigcache.

janisz avatar janisz commented on May 27, 2024 1

In my opinion, we need to carefully consider the trade-off between complexity and usability when evaluating changes to our system. While adding new features can improve functionality, it can also introduce greater maintenance complexity. It's worth exploring other solutions available in the market for in-memory caching, as they may offer better performance or better align with specific requirements. For instance, the Bigcache solution is particularly well-suited for static maps that are not frequently modified after the application startup.

from bigcache.

zsyu9779 avatar zsyu9779 commented on May 27, 2024

So why wasn't a method considered to allow setting expiration time for each cache key?

While it is technically feasible to implement such a feature, it could introduce complexity to the cache system. The bigcache library is based on a circular buffer (i.e., queue.BytesQueue) and does not have a defragmentation process. If we allow every key to be removed at different times, it could result in a significant amount of unused memory. On the other hand, we do allow the removal of a single key, but it is more like marking it as obsolete rather than actually deleting it.

Regarding the problem of memory waste, can we consider designing a compression algorithm? That is, when operating the bytesQueue, record the number of expired keys, and when the number of expired keys reaches a certain threshold, start a compression algorithm to asynchronously create a new, expanded bytesQueue. Then move the data from the old bytesQueue to the new one. During this process, read and write requests are synchronized between the two bytesQueues.

However, this approach does seem to introduce some complexity to the entire system :(

from bigcache.

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.