Module blockedcache

A simple cache for caching values based on x and z coordinates.

Also manages the amount of cached entries and can automatically compact the cache to remove the oldest values.

Functions

BlockedCache:new (max_entries, auto_compact) Creates a new instance of BlockedCache.
BlockedCache:clear () Clears the complete cache.
BlockedCache:compact (max_entries) Compacts the cache, meaning it removes the oldest entries up to the maximum number of entries.
BlockedCache:get (x, z) Gets the value associated with the given x and z coordinates.
BlockedCache:is_cached (x, z) Gets if there is a cache entry associated with the given x and z coordinates.
BlockedCache:put (x, z, value) Puts the value for the given x and z coordinates
BlockedCache:to_string () Gets a string representation of this cache.


Functions

BlockedCache:new (max_entries, auto_compact)
Creates a new instance of BlockedCache.

Parameters:

  • max_entries Optional. The maximum entries for the cache which will be preserved if the cache is compacted, defaults to 12.
  • auto_compact Optional. If the cache performs automatic compaction if the maximum numbers of entries is reached, defaults to true.

Returns:

    A new instance of BlockedCache.
BlockedCache:clear ()
Clears the complete cache.
BlockedCache:compact (max_entries)
Compacts the cache, meaning it removes the oldest entries up to the maximum number of entries.

Parameters:

  • max_entries Optional. The maximum number of cache entries to preserve.
BlockedCache:get (x, z)
Gets the value associated with the given x and z coordinates.

Parameters:

  • x The x coordinate.
  • z The z coordinate.

Returns:

    The value associated with the given x and z coordinates. Returns nil if there is no entry.
BlockedCache:is_cached (x, z)
Gets if there is a cache entry associated with the given x and z coordinates.

Parameters:

  • x The x coordinate.
  • z The z coordinate.

Returns:

    true if there is an entry for the given coordinates.
BlockedCache:put (x, z, value)
Puts the value for the given x and z coordinates

Parameters:

  • x The x coordinate.
  • z The z coordinate.
  • value The value to put.
BlockedCache:to_string ()
Gets a string representation of this cache.

Returns:

    The string representation.
generated by LDoc 1.4.2