8000 GitHub - CIDARO/cobalt: Cobalt is an Open Source LRU Cache written for Deno.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

CIDARO/cobalt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation




Open Source LRU Cache for Deno.

version 1.0.0


Status · Description · TODO List · Usage · Contributing


Status

Cobalt is currently in 1.0.0.


Description

Cobalt is an Open Source LRU Cache for Deno.


TODO List

  • Basic LRUEntry
  • Basic LRUCache (get, set methods)
  • forEach, forEachReverse methods
  • has, pop, reset methods
  • toArray, toArrayReverse methods
  • keys, values methods
  • entries staleness management
  • peek, load methods
  • support different key/value types (or at least support serialization natively)

Usage

Import Cobalt object

In order to import Cobalt in your Deno code you must import it at the top:

import { Cobalt } from "https://deno.land/x/cobalt/mod.ts";

Create new Cobalt object

After you've imported Cobalt, initialize it with the following code:

const cobalt = new Cobalt(); // With default 1000 capacity
const cobaltExpanded = new Cobalt({capacity: 10000}); // Override the default capacity
const cobaltStale = new Cobalt({capacity: 10000, allowStale: true, maxAge: 10}); // Creates a new cobalt cache that allows staleness with objects lasting max 10 seconds

Set, get and remove a key/value pair

With an instantiated Cobalt object you can set, get and remove a key/value pair:

cobalt.set('key', 'test'); // Sets the value 'test' for the key 'test'

cobalt.get('key'); // Returns 'test'

cobalt.remove('key'); // Removes the key from the cache

cobalt.get('key'); // Returns null

Useful functions and properties

These are some of the functions that you can use with a Cobalt object:

cobalt.size; // returns the cache size

cobalt.reset(); // resets th
6BB4
e cache to its starting configuration

cobalt.keys(); // returns an array with all the keys in the cache

cobalt.values(); // returns an array with all the values in the cache

cobalt.has('key'); // returns true if the cache has the 'key' key, false otherwise

cobalt.pop(); // removes the last entry (tail) and returns its value

cobalt.forEach((entry, index) => /* do something */); // iterates through the cache from the MRU to the LRU

cobalt.forEachReverse((entry, index) => /* do something */); // iterates through the cache from the LRU to the MRU

cobalt.toArray(); // returns the cache as an array of entries

cobalt.toArrayReverse(); // returns the cache as a reversed array of entries

Run tests

In order to run the tests, just clone the directory:

git clone https://github.com/CIDARO/cobalt.git

And then run the following code:

cd cobalt
deno test mod.test.ts

Hopefully everything will be ok!


Contributing

We welcome community contributions!

Please check out our open issues to get started.

If you discover something that could potentially impact security, please notify us immediately by sending an e-mail at support@cidaro.com. We'll get in touch with you as fast as we can!

About

Cobalt is an Open Source LRU Cache written for Deno.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0