Git Product home page Git Product logo

cache-base's Issues

add `.default()` method

I think it would be nice to support adding default values that would work like this:

const CacheBase = require('cache-base');
const app = new CacheBase();

app.set('foo', 'xxx');
app.default('foo', 'one');
app.default('bar', 'two');
app.default('baz', 'three');
app.set('baz', 'zzz');

console.log(app.get('foo'));
//=> 'xxx'

console.log(app.get('bar'));
//=> 'two'

console.log(app.get('baz'));
//=> 'zzz'

console.log(app);
// Cache {
//   cache: { foo: 'xxx', bar: 'two', baz: 'zzz' },
//   defaults: { foo: 'one', bar: 'two', baz: 'three' } }

@doowb any thoughts?

Another issue, #5 describes a similar but different approach

denial of service and may lead to remote code execution vulnerability

According to https://app-eu.whitesourcesoftware.com/Wss/WSS.html#!securityVulnerability;id=CVE-2020-28275 there is a

Prototype pollution vulnerability in 'cache-base' versions 0.7.0 through 4.0.0 allows attacker to cause a denial of service and may lead to remote code execution.

in

this.emit('set', key, ...rest);

There seems to be a CVE already assigned: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-28275

Any chance to get this fixed?

TODO: config-cache

potentially use this as a base for config-cache. the only thing I'm having a hard time deciding on is whether or not to allow getting/setting of property paths, e.g.

get('data.foo.bar');
//=> '{foo: {bar: {...}}}'

This can be expensive, but I think if we prevent lookups when the key doesn't have a . it should speed things up. Also, I'm not currently doing any setting of object paths (set('a.b.c', {foo: 'bar'})), but it can be (re)implemented if it's necessary to use this for config-cache.

cc @doowb

remove support for setting on the root of the cache

I've never been a fan of settings values on the root, as it creates potential for conflicts, makes it harder to get the actually user-defined values, et cetera.

I think we should just set values on .cache by default, or a property specified by the user.

The consequence of this change is that you won't be able to directly get or set values from the root of the instance of cacheBase, you'd have to get and set on cacheBase.cache or whatever property was defined.

@doowb any thoughts? can you think of other side effects of removing support for getting/setting on the root of the object? will it materially change how we do things in other libs?

Support for TTL

Hi,

Can't find support for TTL. Would be very usefull.

Thanks

more real `.has` method?

Before was using has-value(s), now is just typeof val !== undefined

also add hasOwn and union methods?

fix documentation or make it real

It shows that default writing is to app.cache but it writes to app.
So, PR for fix or PR for module.exports = namespace('cache')?

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.