Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jacobbubu/capped-event
https://github.com/jacobbubu/capped-event
Last synced: 14 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jacobbubu/capped-event
- Owner: jacobbubu
- License: mit
- Created: 2019-11-17T14:44:14.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T01:03:10.000Z (about 2 years ago)
- Last Synced: 2024-11-13T16:12:01.411Z (2 months ago)
- Language: TypeScript
- Homepage:
- Size: 2.44 MB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: code-of-conduct.md
Awesome Lists containing this project
README
# @jacobbubu/capped-event
[![Build Status](https://travis-ci.org/jacobbubu/capped-event.svg)](https://travis-ci.org/jacobbubu/capped-event)
[![Coverage Status](https://coveralls.io/repos/github/jacobbubu/capped-event/badge.svg)](https://coveralls.io/github/jacobbubu/capped-event)
[![npm](https://img.shields.io/npm/v/@jacobbubu/capped-event.svg)](https://www.npmjs.com/package/@jacobbubu/capped-event/)> A derived class from ReliableEvent in [scuttlebutt-pull](https://github.com/jacobbubu/scuttlebutt-pull) that provides basic cache management capabilities.
## Intro.
The `ReliableEvent` in [scuttlebutt-pull](https://github.com/jacobbubu/scuttlebutt-pull) has not provided cache mechanism.
You can only push events into the instance of `ReliableEvent`, but there is no way to remove them.
In `CappedEvent`, we fire a notification when the items count for some event reached a `warningLine` that is setting by the `options` you passed through the construction.
For removing items from cache, we provide to methods:
- `pruneBefore(before: number, key: string)`: prune the items before xxx milliseconds.
- `pruneTo(remain: number, key: string)`: just keep `remain` items in cache.Please the test case for the detail.