Giter VIP home page Giter VIP logo

Comments (4)

dgilland avatar dgilland commented on June 7, 2024

It may depend on which webserver you are using but a cacheout instance uses a dictionary under-the-hood. Typically you would have a singleton instance of the cacheout instance defined somewhere and then made accessible during web request handling. How you might do that might be influenced by the web framework but ignoring that part, just creating the instance in a module and then importing it would work.

If you are creating separate web worker processes, then just be aware that the cacheout instance from one process wouldn't have access to the cacheout data in another process. But threaded workers should be able to access the same cacheout instance so they would share data.

from cacheout.

ankur09011 avatar ankur09011 commented on June 7, 2024

I am using async FastApi webserver.
Using the same way having a singleton instance of the cacheout instance and using it in parts of code. The problem is I am running the server under gunicorn with 4 workers and every worker is maintains it own cacheout instance. Is there any any I can share that between the workers?

from cacheout.

dgilland avatar dgilland commented on June 7, 2024

You would need to use a data structure that can be shared between processes. That isn't something that is implemented in cacheout right now, but you could override the internals of cacheout to replace the ordered-dictionary implementation with something that works across processes.

For example, the Manager class has a dict method that works across processes. But then you would also need to implement the various ordered-dictionary methods that are used by cacheout as needed for whatever caching strategy you need. You would also need to start the Gunicorn server a certain way as well per https://stackoverflow.com/a/66135571/681166.

So if something like redis is available to you, then that may be a better option or some other Python library that implements multiprocess caching if you want to stick with in-memory caching without a dedicated cache server.

from cacheout.

ankur09011 avatar ankur09011 commented on June 7, 2024

Thank You @dgilland for giving detailed explanation on this. Not want to have a TCP call so not going for Redis.
This is all good for the time being

from cacheout.

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.