Evict
evict
evict(obj)
evict(obj)Evicts an immutable item from the cache. Removes any references of the item existing inside other items.
Parameters
obj
Object | stringeither the object's unique id or the object itself.
Returns:
boolean, true if the item was evicted, false otherwise.
Example
let item = {uid:1}
One.put(item)
One.get(1) === undefined // false
One.evict(1)
One.get(1) === undefined // trueSomething a little more interesting
let item = {uid:1}
let item2 = {
uid:2,
item: item1
}
One.put(item2)
One.get(1) === undefined // false (item1 was put by reference)
One.evict(1)
let cached = One.get(2);
console.log(JSON.stringify(cached)) // {uid:2} item1 is removed by evictionIt works with arrays
Putting an item after removing one of its references also evicts if the reference is the last item in the cache
Or
But not if another entity still references it
Last updated
Was this helpful?