The bucket options, all optional: with none given, values are retained for the life of the process
Optional Readonlyttl?: numberThe 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?: numberThe 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
A fresh, immutable Bucket holding values in memory
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
putis drained into a private buffer, over whichgetopens 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:
Every
getandputcounts 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 nextgetorput, whatever key it addresses; removing a value likewise frees its share of the budget.