Giter VIP home page Giter VIP logo

memory-cache-node's People

Contributors

gabriel8579 avatar kracas avatar luttje avatar pksilen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

memory-cache-node's Issues

Import issue (maybe es6 related)

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.

Item TTL left?

Hey,

is it possible to ask the library how long an item is left "stored" (ie. get its time left in the cache)?

Thanks!

Convert cache to json and vice versa

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

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.