Code Monkey home page Code Monkey logo

Comments (8)

hypirion avatar hypirion commented on May 31, 2024 1

@hypirion Thanks for feedback!

I understand your opinion, but I have one concern. That is the data will remain on memory unless the next Get method is called.

I'm hoping this can be solved, so please, give me some ideas!

Oh, right. https://github.com/patrickmn/go-cache uses one janitor goroutine per cache, which at some user-specified interval removes all expired items from the cache:

https://github.com/patrickmn/go-cache/blob/46f407853014144407b6c2ec7ccc76bf67958d93/cache.go#L1071-L1126

There is a bit more overhead when getting values, as you have to check whether they have expired or not. Perhaps one of those things prevent this from being doable, as I haven't looked too closely at the performance implications of this.

And true, as outlined and tested in https://tpaschalis.github.io/goroutines-size/, the goroutine stack size is minimum 2kb, but could be more -- although I don't think the cleanup routines would go much beyond that.

I'd happy to take a look and make a PR if I find a workable solution that doesn't add too much complexity. If I were to do that I'd still fall back on the original implementation with goroutines though, for backwards compatibility/behaviour.

from go-generics-cache.

GlennRicaud avatar GlennRicaud commented on May 31, 2024 1

I find myself in the same situation. Thousands of ExpirationWatcher goroutines.
I think the idea mentioned above is the right direction: one routine taking care of collecting all expired items.

from go-generics-cache.

Code-Hex avatar Code-Hex commented on May 31, 2024

@hypirion Thanks for feedback!

I understand your opinion, but I have one concern. That is the data will remain on memory unless the next Get method is called.

I'm hoping this can be solved, so please, give me some ideas!

Thanks

from go-generics-cache.

Code-Hex avatar Code-Hex commented on May 31, 2024

And, I don't believe each goroutine size is 2kb. The size meaning for initial stack size.

See https://tpaschalis.github.io/goroutines-size/

from go-generics-cache.

Code-Hex avatar Code-Hex commented on May 31, 2024

@hypirion Thanks. I'm looking forward to the PR you create!

If you have no time, I can make PR for it. So please let me know.

from go-generics-cache.

mingcheng avatar mingcheng commented on May 31, 2024

improved, pls check the code

from go-generics-cache.

Code-Hex avatar Code-Hex commented on May 31, 2024

I've just published the latest version. Thank you for your contributions!

@mingcheng

https://github.com/Code-Hex/go-generics-cache/releases/tag/v1.1.0

from go-generics-cache.

hypirion avatar hypirion commented on May 31, 2024

Thanks for the contribution here! 😁

from go-generics-cache.

Related Issues (8)

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.