Cache¶
- class understand.Cache¶
Bases:
objectCache object
This object can be retrieved from plugin objects and allows plugin scripts to store, retrieve, and share data. It’s essentially a global variable whose lifetime is managed by Understand. At minimum, caches are cleared when the corresponding database is analyzed or closed, but may be cleared more frequently.
Understand maintains a read-only Git cache (retrieved with id=”Git”) that supports the following keys:
cache.value(ent=file,key=”commits”) # List of commits from newest to oldest cache.value(ent=file,key=”authors”) # List of authors corresponding to commits cache.value(ent=file,key=”dates”) # List of iso date strings corresponding to commits
Methods Summary
Clear the cache.
Store a value in the cache.
Return True if the cache is empty
Lock the cache.
cache.lock() -> None
Return the value stored under key and/or entity.
Methods Documentation
- clear() None¶
Clear the cache. Caches are cleared automatically by Understand so scripts won’t normally need to call this unless data external to Understand changes.
- Return type:
None
- insert(value[, key[, ent]]) None¶
Store a value in the cache. Optionally specify a string and/or an entity as keys. The value can be retrieved with
value. Supported values are entities, strings, integers, doubles, and lists of the supported values.- Parameters:
value (str or int or double or list) – the value to store
key (str) – optional, a string identifier
ent (understand.Ent) – optional, an entity identifier
- Returns:
the the stored value
- is_empty() bool¶
Return True if the cache is empty
- Return type:
bool
- Returns:
True if the cache is empty
- lock() None¶
Lock the cache. Careful: users must call unlock()!
Calls reading and writing from the cache are protected for access from multiple threads. This function is only for clients that need additional control over thread access. For example, a CodeCheck script that calculates an entire cache globally could use this function to ensure that other CodeCheck threads block instead of simultaneously performing the expensive calculation.
If lock() is called, unlock() MUST be called.
- Return type:
None
- unlock()¶
cache.lock() -> None
Unlock the cache. Careful: users must have called lock() first!
Calls reading and writing from the cache are protected for access from multiple threads. This function is only for clients that need additional control over thread access. For example, a CodeCheck script that calculates an entire cache globally could use this function to ensure that other CodeCheck threads block instead of simultaneously performing the expensive calculation.
The lock() call must be called before this call.
- Return type:
None
- value([key[, ent[, value]]]) value¶
Return the value stored under key and/or entity. See
insertfor saveable values. Use the value parameter to give a return value when the key/entity is not in the cache. The value parameter defaults to None.- Parameters:
key (str) – optional, a string identifier
ent (understand.Ent) – optional, an entity identifier
value – optional, a return value if the key/entity pair was not in the cache
- Returns:
the stored value or None if none stored