Giter Club home page Giter Club logo

Comments (1)

bitfaster avatar bitfaster commented on May 30, 2024

The ItemRemoved event has both key and value - probably not the most convenient but gives you a way to observe removed values without a false lookup that can pollute cache ordering.

This is complicated by the lifetime of IDisposable values. If values are disposable, the cache will auto dispose them on removal. A TryRemove that returns the value would then either need to be a special case, where the caller must dispose the live value returned (which isn't intuitive, and likely one might forget and leak objects), or it would return disposed objects, which may not be valid and may throw if methods are invoked etc. Neither option is great. My rationale here was to do the simplest thing and not expose any potential traps.

The ItemRemoved event fires before disposal, so the value is still alive when the event handler runs. Thus it sidesteps the above.

I suspect caching IDisposable is less common, so it's unfortunate to limit the common case to keep this clean, but that was my tradeoff.

Changing the signature would be a breaking change - I will consider for the next major version, but I'm inclined not to add this.

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.