local-lru-cache

1.0.1 • Public • Published

Welcome to local-lru-cache 👋

Version Documentation Maintenance License: MIT

A local cache module

Example

const LocalCache = require('local-lru-cache')

// 1.create LocalCache
const localCache = new LocalCache(5)
localCache.set(1, 'a')
localCache.set(2, 'b')
localCache.get(1)         // a
localCache.get(2)         // a,b

// 2.key with expiration time will be delete after expirate (regularly+lazy)
; (async () => {
        localCache.set(3, 'c', 2000)
        await new Promise(resolve => {
            setTimeout(resolve, 2000)
        })
        localCache.get(3)  // null
})()

/**
 * 3. LRU memory elimination strategy
 *    3.1 only eliminate keys without expiration time
 *    3.2 elimination when localCache.size > cache.size+expireCache.size
 * */
localCache.set(3, 'c',2000) // a,b,c
localCache.set(4, 'd')      // a,b,c,d
localCache.set(5, 'e')      // a,b,c,d,e
localCache.set(6, 'f')      // b,c,d,e,f
localCache.set(7,'g')       // c,d,e,f,g
localCache.set(8,'h')       // c,e,f,g,h

🏠 Homepage

Install

npm install

Author

👤 selenium39

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2021 selenium39.
This project is MIT licensed.


This README was generated with ❤️ by readme-md-generator

Readme

Keywords

Package Sidebar

Install

npm i local-lru-cache

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

5.91 kB

Total Files

4

Last publish

Collaborators

  • selenium39