Comments (8)
@cjaoude you write one singleton module that exports a cache instance and import that one instance everywhere you want to use it.
Example:
./src/cache.js:
const NodeCache = require("nodecache");
module.exports = new NodeCache(/* your nodecache settings here */);
./src/a.js
const cacheSingleton = require("./cache.js");
// cacheSingleton is the same cache instance everywhere inside your app
// as long it runs inside the same node.js process
./src/b.js
const cacheSingleton = require("./cache.js");
// cacheSingleton is the same cache instance everywhere inside your app
// as long it runs inside the same node.js process
This is not specific to NodeCache but more how the node.js module system works. Read more at: https://nodejs.org/dist/latest-v10.x/docs/api/modules.html
from node-cache.
How to access the same cache in a different module? Seems pointless to have a cache just for one file. (same app) Tnx
from node-cache.
Thats not possible.
The usecase of node-cache is a cache within one running node process.
You can compare it to a advanced JavaScript object.
It's a planned feature to define a storage provider like process memory, a file or a external server solution.
But for now I recommend using a memcached or redis server that's saving your data.
from node-cache.
Would there be any security or performance issues with putting a cache instance on app.locals in an express app?
from node-cache.
@CalebEverett node-cache for itself has no security built in.
Putting the node-cache to the app.locals of express is a possible solution.
I don't know any security issues of app.locals
, but i recommend to asking this question directly to express.
from node-cache.
What happens if you run nodecache in an app running in cluster mode, say, like in pm2? Does this mean that each thread will have its own cache?
from node-cache.
@amenadiel Cluster mode or event pm2 cluster ist currently not development target and is not tested yet. Fell free to check it and tell me the results or send me a PR ;-)
from node-cache.
I see, thanks, that makes sense. @erdii
from node-cache.
Related Issues (20)
- can we do something like if it's not accessed for x amount of time delete it? HOT 1
- General cache stats HOT 1
- Make NodeCache compliant con the Map interface on future releases
- Persisting node-cache HOT 6
- What does negative vsize value mean?
- Takes long time to cache (set&get) large JSON objects HOT 2
- Invalidate cache from command line tool HOT 1
- Expired value HOT 1
- useClone on a value by value basis
- Use one instance of NodeCache per DB collection... HOT 2
- Bug report
- Lack of fetch function HOT 1
- It costs too much time!!!!!!!!! HOT 2
- Is there any reason why this can't be used on the frontend? HOT 4
- node-cache is automatically empty on node js vercel deployment HOT 2
- Can I access the cache across different script? HOT 3
- Recursive call: RangeError: Maximum call stack size exceeded when deleteOnExpire:false
- Event on Cache eviction HOT 2
- TS Errors for .d.ts file of the package
- Is this project still maintained? HOT 1
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 node-cache.