New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@jamesbontempo/typecache

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jamesbontempo/typecache - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

3

package.json
{
"name": "@jamesbontempo/typecache",
"version": "0.1.3",
"version": "0.1.4",
"description": "A simple TypeScript caching library with ttl support and SQL-inspired syntax",

@@ -16,2 +16,3 @@ "files": [

"cache",
"ttl",
"TypeScript",

@@ -18,0 +19,0 @@ "SQL"

@@ -23,29 +23,58 @@ # typecache

```
## Contents
- [Constructor](#constructor)
- [Cache properties](#cache-properties)
- [Cache methods](#cache-methods)
- [Cache item methods](#cache-item-methods)
- [Cache events](#cache-events)
## Constructor
Creates a new `TypeCache` instance. By default, there is no `ttl` & all items persist until deleted, or until the cache itself is cleared or destroyed.
Creates a new `TypeCache` instance. By default, there is no `ttl` (actually, it's set to `Infinity`) & all items persist until deleted, or until the cache itself is cleared or destroyed.
## Cache properties
`count` The number of items in the cache.
`count`
`ttl` The default ttl in milliseconds for items inserted into the cache. You can "get" or "set" this value.
The number of items in the cache.
`ttl`
The default ttl in milliseconds for items inserted into the cache. You can "get" or "set" this value.
## Cache methods
`keys()` Returns an array of the cache keys.
`keys()`
`clear()` Removes all items from the cache.
Returns an array of the cache keys.
`clear()`
Removes all items from the cache.
## Cache item methods
`insert(key, value [, ttl, force])` Inserts an item into the cache. If no `ttl` is provided the default cache-level ttl is used. If an item already exists for the given key and `force` is `true` the item will effectively be overwritten (both its `value` and its `ttl`); otherwise, no changes will be made.
`insert(key, value [, ttl, force])`
`update(key, value)` Updates the value of the item in the cache.
Inserts an item into the cache. If no `ttl` is provided the default cache-level `ttl` is used. If a `ttl` value less than or equal to zero is provided it's ignored. If an item already exists for the given key and `force` is `true` the item will effectively be overwritten (both its `value` and its `ttl`); otherwise, no changes will be made.
`remaining(key)` Returns the remaining `ttl` time for the item; that is, how much longer before the item is removed from the cache.
`update(key, value)`
`extend(key [, ttl])` Extends the `ttl` of the item by a number of milliseconds. If no `ttl` is provided the default cache-level ttl is used (allowing you to basically "bump" the item). If a `ttl` of `Infinity` is provided, the `ttl` is effectively removed.
Updates the value of the item in the cache.
`shorten(key, ttl)` Shortens the `ttl` of the item by a number of milliseconds. If the current `ttl` is less than the value provided no changes are made because the item would be deleted before the shortened time anyway. If the current `ttl` is `Infinity` sets the `ttl` to the value provided.
`remaining(key)`
`delete(key)` Deletes the item from the cache.
Returns the remaining `ttl` time for the item; that is, how much longer before the item is removed from the cache. If there is no `ttl` it will return `Infinity`.
`extend(key [, ttl])`
Extends the `ttl` of the item by a number of milliseconds. If no `ttl` is provided the default cache-level ttl is used (allowing you to basically "bump" the item). If a `ttl` of `Infinity` is provided, the `ttl` is effectively removed.
`shorten(key, ttl)`
Shortens the `ttl` of the item by a number of milliseconds. Values less than or equal to zero are ignored. If the current `ttl` is less than the value provided no changes are made because the item would be deleted before the shortened time anyway. If the current `ttl` is `Infinity`, the `ttl` is set to the value provided.
`delete(key)`
Deletes the item from the cache.
## Cache events

@@ -59,3 +88,3 @@

value: key value,
ttl: ttl,
ttl: key ttl,
added: when the key was added,

@@ -67,8 +96,14 @@ modified: when the key was modified,

`insert` Emits information about the item inserted.
`insert`
`update` Emits information about the updates to an item. Includes `before` and `after` objects allowing for comparison.
Emits information about the item inserted.
`delete` Emits information about the item deleted. Useful to "listen" for `ttl` expirations.
`update`
Emits information about the updates to an item. Includes `before` and `after` objects allowing for comparison.
`delete`
Emits information about the item deleted. Useful to "listen" for `ttl` expirations.
This allows you to do something like this:

@@ -75,0 +110,0 @@ ```js

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