Skip to content

diskCache.set is not a function when using the example on readme.. #42

@taltal78

Description

@taltal78

Code from readme gives diskCache.set is not a funciton... is this library still valid ?

// node cachemanager
var cacheManager = require('cache-manager');
// storage for the cachemanager
var fsStore = require('cache-manager-fs');
// initialize caching on disk
const diskCache = cacheManager.caching({
    store: fsStore,
    options: {
        path: 'diskcache',          //path for cached files
        ttl: 60 * 60,               //time to life in seconds
        maxsize: 1000*1000*1000,    // max size in bytes on disk
        zip: true,                  //zip files to save diskspace (default: false)        
        preventfill:true
    }
});

(async () => {

    await diskCache.set('key', 'value');
    console.log(await diskCache.get('key')); //"value"
    console.log(await diskCache.ttl('key')); //3600 seconds
    await diskCache.del('key');
    console.log(await diskCache.get('key')); //undefined

    console.log(await getUserCached(5)); //{id: 5, name: '...'}
    console.log(await getUserCached(5)); //{id: 5, name: '...'}

    await diskCache.reset();

    function getUserCached(userId) {
        return diskCache.wrap(userId /* cache key */, function () {
            return getUser(userId);
        });
    }

    async function getUser(userId) {
        return {id: userId, name: '...'};
    }

})();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions