@metreeca/core - v0.9.22
    Preparing search index...

    Function createMemoryBucket

    • Creates an in-memory bucket.

      The generated Bucket holds values in the process heap, so that content is kept with no external service and no setup, at the price of being confined to the process and lost when it exits. A stream handed to put is drained into a private buffer, over which get opens a fresh stream on every call, so retained content counts in full against the heap budget of the process and never shares storage with the bytes a caller streams in or out.

      Called with no options, the bucket retains every value for the life of the process; given a time to live, values left unused for longer are dropped; given a byte budget, values beyond it are dropped in least recently used order:

      const cache = createMemoryBucket({ ttl: 60_000, bytes: 1_000_000 });
      

      Every get and put counts as a use, restarting the time to live of the value and making it the most recently used one, so a value is dropped only once left untouched for a whole time to live, or once every other retained value has been used more recently. Expiry is checked on access rather than on a timer, so an expired value is never handed out and stops counting against the byte budget on the next get or put, whatever key it addresses; removing a value likewise frees its share of the budget.

      Parameters

      • options: { ttl?: number; bytes?: number } = {}

        The bucket options, all optional: with none given, values are retained for the life of the process

        • Optional Readonlyttl?: number

          The number of milliseconds a value is retained for after its last use, dropping it once they elapse; a value less than or equal to 0 retains values indefinitely, as the default does

        • Optional Readonlybytes?: number

          The total number of value bytes to be retained, dropping the least recently used values beyond that, a value exceeding the budget on its own included; a value less than or equal to 0 leaves the bucket unbounded, as the default does

      Returns Bucket

      A fresh, immutable Bucket holding values in memory