Code Monkey home page Code Monkey logo

Comments (12)

jodydonetti avatar jodydonetti commented on June 10, 2024 1

Hi @giulianob , I'm looking into this right now.
I'd like to avoid releasing a new version in a rush, so if I can find a quick temporary workaround I'll tell you right away.
Will update you asap.

from fusioncache.

giulianob avatar giulianob commented on June 10, 2024 1

Yeah pre-release would be fine. Thanks!

from fusioncache.

jodydonetti avatar jodydonetti commented on June 10, 2024

Hi @giulianob and thanks for using FusionCache!

A couple of points.

I may add a FusionCacheEntryOption to auto-dispose a value when evicted, so that you may have granular control per each cache entry. Of course as always you may then set this in the DefaultEntryOptions once and it will be used as a default for all entries.
Sounds good?

What do you think should happen when a value is being set (either by calling a Set(), GetOrSet() or because of a remote notification from the backplane, etc) and there's an override? I'm not 100% sure IMemoryCache always considers this an eviction even though here there's a Replaced value (anyway I'll check and do some tests), so I would like to know if in this case you would also like to dispose, since the old value is being overwritten.
Ofcourse in that case I should also probably check for the fact that the new value is different from the old one, otherwise a piece of code like this:

var myDisposable = new MyDisposable();

cache.Set("foo", myDisposable);
cache.Set("foo", myDisposable);

would end up disposing the very object we are about to set.

Let me know what you think, thanks.

from fusioncache.

jodydonetti avatar jodydonetti commented on June 10, 2024

In the meantime I was also thinking about this: as we know a memory cache stores live object references, therefore when you get something from the cache you are using exactly the same instance.

This means that if you get something from the cache and then it gets disposed, you'll end up working on a disposed object, with all the problems this will create.

A practical example:

var myDisposable = new MyDisposable();

cache.Set("foo", myDisposable, TimeSpan.FromSeconds(2));

var foo = cache.GetOrDefault<MyDisposable>("foo");

// 2 SEC LATER...

if (foo is not null) {
  // THIS WILL PROBABLY THROW AN ObjectDisposedException
  foo.Whatever();
}

What do you think?

from fusioncache.

giulianob avatar giulianob commented on June 10, 2024

In my scenario, I am making sure to set the duration longer than the amount of time the object can be referenced (the request timeout in my case). You do need to be careful. I am storing objects that must be disposed to free up resources rather than waiting for GC to occur.

from fusioncache.

giulianob avatar giulianob commented on June 10, 2024

@jodydonetti Is there any workaround available to get the item being evicted in the callback?

from fusioncache.

jodydonetti avatar jodydonetti commented on June 10, 2024

I think I need to release a new version, there's no other way around it.

I'll try to release it tomorrow night.

Just to be sure: a pre-release version would be ok right?

from fusioncache.

jodydonetti avatar jodydonetti commented on June 10, 2024

Hi all, the v0.24.0-preview1 pre-release is out now on Nuget 🎉

NOTE: remember to check the "include prerelease" checkbox in your IDE to see it!

from fusioncache.

jodydonetti avatar jodydonetti commented on June 10, 2024

Ho @giulianob , did you have time to check this?

Thanks!

from fusioncache.

giulianob avatar giulianob commented on June 10, 2024

Yes, exactly what I needed. Thanks!

from fusioncache.

jodydonetti avatar jodydonetti commented on June 10, 2024

Awesome, thanks 🥳

Will close this when the non-preview next version will be release.

from fusioncache.

jodydonetti avatar jodydonetti commented on June 10, 2024

Hi all, the v0.24.0 release is out now on Nuget 🎉

It is a massive release with a lot of new features, optimizations and more, I suggest to check out the release notes.

from fusioncache.

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.