Comments (4)
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.
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.
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.
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)
- cacheout
- Are the default functions single-threaded? HOT 2
- Roadmap "Layered caching (multi-level caching)" HOT 2
- The in operator returns True after cache expiration HOT 2
- OrderedDict Mutated during Iteration HOT 1
- Using cacheout in the context of multiprocessing HOT 1
- how about add a callback to expired object? HOT 1
- Update expire time for specific entrys HOT 2
- Why not using cache[key] = value? HOT 3
- TTL setting is unclear according to the documentation HOT 1
- Can you add a new cache algorithm?
- Eviction callback HOT 7
- Cache statistics HOT 17
- on-get callback HOT 6
- on-set callback HOT 9
- A typo in docstring? HOT 1
- single key info HOT 1
- sanic web framework will it be safe ? HOT 1
- An error in LFU? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cacheout.