Page tree
Skip to end of metadata
Go to start of metadata

Introduced in



Description:Initializes a cache for use in fn vbs cachedEval and sets the parameters used to maintain it.

This can also be used to change the parameters of an existing cache after initialization, without clearing the data it currently holds.


Syntax:[cache, maxsize, cleansize, cleanmode, arrayinput] call fn_vbs_cacheInit
  • cache: String or Array - Empty array or string name of a global variable to use as a new or existing cache.
  • maxsize: Number - Once the cache reaches this size (in number of different inputs stored), the cache is cleaned up, and the elements are removed to reduce the size to cleansize. If 0, cache can be of unlimited size (optional, default 0).
  • cleansize: Number - Cache is reduced to this size once it surpasses maxsize. If 0, cleansize is 90% of maxsize (optional, default 0).
  • cleanmode: Number - Method by which to reduce cache to cleansize (optional, default 0):
    • 0 - Remove least frequently used data.
    • 1 - Remove least recently used data.
    • 2 - Remove most frequently used data.
    • 3 - Remove most recently used data.
    • 4 - Reset entire cache (cleansize is ignored with this option).
  • arrayinput: Boolean - Determines the method used to access cache. Cache access is faster if false (optional, default: false):
    • Use true, if either of the following applied:
      • Arrays might be used as inputs in this cache.
      • String input should be case-insensitive.
    • Use false, if either of the following applied:
      • Only non-array data is used.
      • String input should be case-sensitive.
Return Value:Boolean - Returns true if successful, false if not. Most likely cause of failure is passing a nil variable.


When using functions in VBS versions older than 3.4, certain limitations and requirements should be kept in mind - the main ones being that capitalization of the function name is crucial, and that #include "\vbs2\headers\function_library.hpp" has to be included in every script that utilizes it. More Category VBS Scripting Functions.


["mycache", 100, 150, 2, true] call fn_vbs_cacheInit

Additional Information

See also: fn vbs cachedEval, fn vbs cacheDiag


The optimal cache parameters (max size, cleanup type) depend on the situation the cache is used in, and require a lot of trial and error to determine. You can use the function
fn vbs cacheDiag
to monitor the status of the cache, which can help you run tests with different cache parameters until you find the "best" setup. --
General Barron
22:47, 30 December 2009 (CET)