Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hscmap/cache-map

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hscmap/cache-map

CacheMap is an Es6's Map-like collection class with a limit of number of items. The limit must be specified at initialization time. ## Install ```sh npm install --save @hscmap/cache-map ```

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17
decreased by-45.16%
Maintainers
1
Weekly downloads
 
Created
Source

Introduction

CacheMap is an Es6's Map-like collection class with a limit of number of items. The limit must be specified at initialization time.

Install

npm install --save @hscmap/cache-map

Example

import { CacheMap } from "@hscmap/cache-map"
import * as _ from 'lodash'


const assert = (test: boolean) => console.assert(test)


!(function withoutPersistentItem() {
    const dropLog: number[] = []
    const cm = new CacheMap<string, number>(3, v => dropLog.push(v))

    cm.set('one', 1)
    cm.set('two', 2)
    cm.set('three', 3)

    assert(cm.get('one') == 1)
    assert(cm.get('two') == 2)
    assert(cm.get('three') == 3)

    cm.set('four', 4)
    assert(cm.get('four') == 4)
    assert(cm.get('one') == undefined)

    assert(cm.get('two') == 2)
    cm.set('five', 5)
    assert(cm.peek('two') == 2)
    assert(cm.peek('three') == undefined)

    assert(cm.size == 3)
    assert(_.isEqual(dropLog, [1, 3]))

    cm.clear()
    assert(cm.size == 0)
    assert(_.isEqual(dropLog, [1, 3, 4, 2, 5]))

    cm.set('one', 1)
    cm.set('two', 2)

    cm.delete('one')
    assert(cm.get('one') == undefined)
    assert(cm.size == 1)

})()


!(function test2() {
    const dropLog: number[] = []
    const cm = new CacheMap<string, number>(3, v => dropLog.push(v))

    cm.set('one', 1, true)
    cm.set('two', 2)
    cm.set('three', 3, true)
    cm.set('four', 4)
    cm.set('five', 5)
    cm.set('six', 6)
    cm.set('seven', 7)
    assert(cm.peek('one') == 1)
    assert(cm.peek('two') == undefined)
    assert(cm.peek('three') == 3)
    assert(cm.peek('four') == undefined)
    assert(cm.size == 5)
    assert(_.isEqual(dropLog, [2, 4]))
})()

FAQs

Package last updated on 07 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc