Code Monkey home page Code Monkey logo

Comments (7)

BryanDonovan avatar BryanDonovan commented on August 17, 2024

You probably just need to require() the file.

from cacheable.

chsukhesh-zz avatar chsukhesh-zz commented on August 17, 2024

can you please give a example.
you mean get the cache variable from one into new js file, OR
Already I imported cache-manager in both js files.

from cacheable.

BryanDonovan avatar BryanDonovan commented on August 17, 2024

I might not be understanding the issue, but I'm guessing you have something like:

cache.js:

const cacheManager = require('cache-manager');
const memoryCache = cacheManager.caching({store: 'memory', max: 100, ttl: 10/*seconds*/});

// some custom code.. e.g.,

const myCacheModule = {
   myFunc(args, cb) {
      memoryCache.get ....
   }
 // etc.
};

module.exports = myCacheModule;

Then in another file:

const myCacheModule = require('./cache');
// do stuff..

from cacheable.

chsukhesh-zz avatar chsukhesh-zz commented on August 17, 2024

Thank you very much but,
What i am doing is -

A.js

   var cacheManager = require('cache-manager');
   var memoryCache = cacheManager.caching({store: 'memory', max: 1000, ttl: 90/*seconds*/});
    memoryCache.set('a',user, {ttl: ttl}, function(err) {
        if (err) {
            callback({'Error':true,'Message':err});
            console.log('error of user repo',err);
         }else {
            console.log("SucessFully added to cashe");
            callback(undefined,"SucessFully added to cashe");
        }

        });

B.js

       var cacheManager = require('cache-manager');
       var memoryCache = cacheManager.caching({store: 'memory', max: 1000, ttl: 90/*seconds*/});

       memoryCache.get('a', function(err, result) {
        if(err){
            callback({'Error':true,'Message':"session is end"});
            console.log('session is end',err);
        }
        else{
            console.log(result);
            callback(undefined,result);
        }
    });

from cacheable.

BryanDonovan avatar BryanDonovan commented on August 17, 2024

You can make a third file that just exports your memoryCache instance. E.g.,

myMemoryCache.js

var cacheManager = require('cache-manager');
var memoryCache = cacheManager.caching({store: 'memory', max: 1000, ttl: 90/*seconds*/});

module.exports = memoryCache;

Then from A.js and B.js, just require that file:

var memoryCache = require('./myMemoryCache.js');

from cacheable.

chsukhesh-zz avatar chsukhesh-zz commented on August 17, 2024

Thank you very much, It's perfectly working.

from cacheable.

BryanDonovan avatar BryanDonovan commented on August 17, 2024

No problem!

from cacheable.

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.