1.0.0 • Published 9 months ago

cacheu v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Cacheu(Cache you)


Cache your data in browser memory.

When you use SPA mode to run website, if you don't want to save data in store(redux or vuex) or window object, you can use this.

NPM build npm

Install

npm install cacheu --save

Usage


import Cacheu from 'cacheu';

Interface


1. Cache.create(Object): void

Property nameTypeDefaultDescription
ttlnumber600(s)The time the data is kept
cleanupnumber3600(s)Time to automatically clean up expired data
persistPrefixKeystringCACHEprefix key stored in localStorage

2. Cache.set(key, value, expires, persist): void

Property nameTypeDefaultDescription
keystringN/ARecognizable and unique name in the cache
valueanyN/AStored value
expiresnumber600(s) same as ttlExpiration time set for a single data, set to 0 for permanent existence
persistbooleanfalseWhether to persist data

3. Cache.get(key, defaultValue): any

Property nameTypeDefaultDescription
keystringN/ARecognizable and unique name in the cache
defaultValuestring/nullnulldefault value

4. Cache.has(key): boolean

Property nameTypeDefaultDescription
keystringN/ARecognizable and unique name in the cache

5. Cache.remove(key): void

Property nameTypeDefaultDescription
keystringN/ARecognizable and unique name in the cache

6. Cache.removeAll(): void

  • remove all cache data

Getting Started


index.js

import React from 'react';
import ReactDOM from 'react-dom';
import App from 'app';
import Cacheu from 'cacheu';

Cacheu.create({
  ttl: 600,
  cleanup: 3600,
  persistPrefixKey: 'CACHE',
});

// Set value
Cacheu.set('name', 'James', Cache.config.ttl, true);

ReactDOM.render(<App />, document.getElementById('app'));

App.js

import React from 'react';
import Cacheu from 'cacheu';

const App = () => {
  // Get value
  const name = Cacheu.get('name');
  
  return (
    <div>My name is {name}</div>
  );
};

export default App;

License


MIT

1.0.0

9 months ago

0.1.1

4 years ago

0.0.1

9 years ago