pksilen / memory-cache-node Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
As per documentation, the way to import the MemoryCache
class is
import { MemoryCache } from 'memory-cache-node';
which doesn't work because MemoryCache is exported as default
- as per MemoryCache.d.ts
:
export default class MemoryCache<K, V>
and the above import statement gives SyntaxError: The requested module 'memory-cache-node' does not provide an export named 'MemoryCache'
error.
So the import that actually works is
import MemoryCache from 'memory-cache-node';
But then you gotta use it like
const cache = new MemoryCache.MemoryCache<string, number>(30, 50000);
otherwise you get TypeError: object is not a constructor
.
I'm using es6 modules, if it's relevant.
Hello,
Is there any way to limit cache by size rather than item count?
Hey,
is it possible to ask the library how long an item is left "stored" (ie. get its time left in the cache)?
Thanks!
Hi
What about adding support for converting the cache to json and vice versa? This way I can save/load it to/from a file for when the server restarts.
convertCacheToJson(): string {
const json = Object.fromEntries(this.itemKeyToItemValueWrapperMap);
return JSON.stringify(json);
}
convertJsonToCach(json: string): number {
const tempMap = new Map(Object.entries(JSON.parse(json)));
this.clear();
for (const entry of tempMap.entries()) {
this.itemKeyToItemValueWrapperMap.set(...);
}
return this.getItemCount();
}
I saw that itemKeyToItemValueWrapperMap is readOnly and I didn't want to break your code/pattern so I was thinking of using a temporary map but got lost in the middle. What do you think?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.