Atlantiraptor Docs

cache

Type: Function

Creates a cache object.

A Cache is a data structure which is used to speed up calculating data by keeping its value in memory. A cache is essentially a key value store - when the key is accessed, the function will be calculated producing a value. If the key is accessed again, the value is returned from the cache without calculating it again.

For example consider the following:

LET get_pid_query(Lpid) =
  SELECT Pid, Ppid, Name FROM pslist(pid=Lpid)

LET _ <= cache(lambda='x=>get_pid_query(Lpid=x)[0]')

SELECT cache(key=getpid())
FROM scope()

The cache will ensure that get_pid_query() is only called once per unique Pid by comparing the key against the internal memory store.

Argument Type Description
func LazyExpr A function to evaluate (deprecated - use a lambda instead)
lambda vfilter.Lambda A VQL lambda to evaluate with the key as parameter. e.g.. x=>x+1
name string The global name of this cache (needed when more than one)
key Any Cache key to use.
period int64 The latest age of the cache.
filename accessors.OSPath Filename for a persistent cache.
max_size uint64 Maximum size of the LRU (default 10000).

Required permissions: FILESYSTEM_WRITE

Platforms: macOS, Linux, Windows

Source: vql/tools/lru/cache.go