0.1.1 • Published 3 years ago

cacheu v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years 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. Cacheu.create(Object)

Property nameTypeDefaultDescription
ttlInteger600(s)The time the data is kept
cleanupInteger3600(s)Time to automatically clean up expired data

2. Cacheu.set(key, value, expire)

Property nameTypeDefaultDescription
keyStringN/ARecognizable and unique name in the cache
valueAnyN/AStored value
expireInteger600(s)Expiration time set for a single data, set to 0 for permanent existence

3. Cacheu.get(key)

Property nameTypeDefaultDescription
keyStringN/ARecognizable and unique name in the cache

4. Cacheu.has(key)

Property nameTypeDefaultDescription
keyStringN/ARecognizable and unique name in the cache

5. Cacheu.remove(key)

Property nameTypeDefaultDescription
keyStringN/ARecognizable and unique name in the cache

6. Cacheu.removeAll()

7. Cacheu.isExpired(time)

Property nameTypeDefaultDescription
timeIntegerN/ATimestamp

8. Cacheu.cleanup()

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
});

// Set value
Cacheu.set('name', 'James');

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