https://github.com/naturalintelligence/thds
Time Sensitive Data Structure
https://github.com/naturalintelligence/thds
Last synced: 4 months ago
JSON representation
Time Sensitive Data Structure
- Host: GitHub
- URL: https://github.com/naturalintelligence/thds
- Owner: NaturalIntelligence
- License: mit
- Created: 2024-09-13T04:42:56.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-14T12:21:53.000Z (almost 2 years ago)
- Last Synced: 2025-10-20T10:54:31.902Z (8 months ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# thds
Time Handling Data Structure in Java script
## Expirable List
Entries moves to list of expired elements after a certain time. And deleted after defined conditions are met. You can use this datatype in multiple ways, Eg
- deleting sessions after a predefined inactive time.
- cache management
- token expiry
```js
const ExpirableList = require("tsds/ExpirableList");
const onExpiry = (key, data) => { ... };
const onCleanup = () => { ... };
const list = new ExpirableList({
entryLifespan: 1000,
cleanupInterval: 2500,
maxExpiredEntries: 1000
},onExpiry, onCleanup);
list.add(12345);
list.add("abc", { data: "something"});
list.add("custom life", { data: "something"}, 1500);
const data = list.get("abc");
:
list.delayExpiry("abc"), 600);
:
list.pause(); // pause the list to expire any existing entity
list.resume();
:
list.life(12345); // how long a key is in this list
list.removeEntry(12345);
:
list.forEachExpired((k,v)=>{
:
});
list.forEachNonExpired((k,v)=>{
:
});
:
list.clean(); //to manually clean the list of expired entities
```