View Source DetsPlus.LRU (DetsPlus v2.4.3)

DetsPlus.LRU Least-Recently-Used cache based on DetsPlus persistent storage.

Example:

alias DetsPlus.LRU

{:ok, dets} = DetsPlus.open_file(:example)
filter = fn value -> value != nil end
max_size = 2
lru = LRU.new(dets, max_size, filter)
LRU.put(lru, 1, "1")
LRU.put(lru, 2, "2")
LRU.put(lru, 3, "3")
LRU.get(lru, 1) == nil

DetsPlus.close(dets)

Summary

Functions

Deletes a value from the cache.

Fetches a value from the cache, or calculates it if it's not found.

Fetches a value from the cache, or calculates it if it's not found.

Returns the filter function of the cache.

Flushes the cache deleting all objects.

Gets a value from the cache.

Returns the maximum size of the cache.

Puts a value in the cache.

Returns the size of the cache.

Returns the keys and values of the cache.

Updates a value in the cache.

Functions

Deletes a value from the cache.

Parameters

  • lru - The LRU cache.
  • key - The key to delete.

Fetches a value from the cache, or calculates it if it's not found.

Parameters

  • lru - The LRU cache.
  • key - The key to fetch the value for.
  • fun - The function to calculate the value if it's not found.
Link to this function

fetch_nolock(lru, key, fun)

View Source

Fetches a value from the cache, or calculates it if it's not found.

Same as fetch/3, but without locking.

Parameters

  • lru - The LRU cache.
  • key - The key to fetch the value for.
  • fun - The function to calculate the value if it's not found.

Returns the filter function of the cache.

Parameters

  • lru - The LRU cache.

Flushes the cache deleting all objects.

Parameters

  • lru - The LRU cache.
Link to this function

get(lru, key, default \\ nil)

View Source

Gets a value from the cache.

Parameters

  • lru - The LRU cache.
  • key - The key to get the value for.
  • default - The default value to return if the key is not found.

Returns the maximum size of the cache.

Parameters

  • lru - The LRU cache.
Link to this function

new(dets, max_size, filter \\ fn _ -> true end)

View Source

Creates a new LRU cache.

Parameters

  • dets - The DetsPlus storage to use.
  • max_size - The maximum number of items to store.
  • filter - A filter function that determines if a value should be stored or not.

Puts a value in the cache.

Parameters

  • lru - The LRU cache.
  • key - The key to store the value under.
  • value - The value to store.

Returns the size of the cache.

Parameters

  • lru - The LRU cache.

Returns the keys and values of the cache.

Parameters

  • lru - The LRU cache.

Updates a value in the cache.

Parameters

  • lru - The LRU cache.
  • key - The key to update.
  • fun - The function to calculate the new value.