Nameless Package Manager

    bitecache
    TypeScript icon, indicating that this package has built-in type declarations

    1.2.0 • Public • Published

    Bitecache

    Version Build Status Coverage Status

    A tiny, in-memory cache manager that won't bite you :-)

    Basic usage

    const cache = require("bitecache")
    
    // Create a "users" cache collection with 20 seconds expiration,
    // and a "products" with expiration in 10 minutes.
    cache.setup("users", 20)
    cache.setup("products", 600)
    
    // Add a new user with cache key "jdoe".
    const user = {name: "John", surname: "Doe"}
    cache.set("users", "jdoe" user)
    
    // Get John Doe from cache.
    const cachedUser = cache.get("users", "jdoe")
    
    // You can also merge data to existing cached objects.
    cache.merge("users", "jdoe", {surname: "New Doe"})
    
    // A user that does not exist, will return null.
    const invalidUser = cache.get("users", "invalid")
    
    // Remove user from cache.
    cache.del("users", "jdoe")
    
    // Individual cache items can also have their own expiresIn, here we add
    // a product that expires in 30 seconds instead of the 10 mminutes default.
    cache.set("products", "myproduct", {title: "My Product"}, 30)
    
    // Log cache's total size, estimation of memory size, and cache misses.
    console.log("Total size", cache.totalSize)
    console.log("Total memory size", cache.totalMemSize)
    console.log("Total misses", cache.totalMisses)
    
    // Log individual cache collection stats.
    console.dir(cache.stats("users"))
    
    // Clear the users cache or all cache collections.
    cache.clear("users")
    cache.clear()

    Install

    npm i bitecache

    DownloadsWeekly Downloads

    2

    Version

    1.2.0

    License

    MIT

    Unpacked Size

    12.9 kB

    Total Files

    7

    Last publish

    Collaborators

    • igoramadas