ScopedCacheManager - Scoped
-
- UpdatedJan 30, 2025
- 5 minutes to read
- Yokohama
- API reference
The ScopedCacheManager API provides methods for retrieving, setting, and flushing cache data for scoped applications.
This API requires the Scoped Cache (com.glide.scopedcache) plugin and runs in the sn_scoped_cache
namespace. The plugin is installed and activated by default.
These methods require one or more scoped caches and scoped cache pairs to be defined. For more information on creating scoped caches, see the ScopedCacheManager API Developer Guide.
- Caching strings in scoped applications that live in memory across transactions.
- Caching scoped application data in memory and flushing this data based on changes in the underlying table.
- Defining and use cache data outside the transaction life cycle.
- Caching the output of expensive operations or calculations for quick access in the future.
ScopedCacheManager – flushScopedCache(String catalog, String key)
Flushes an entire cache or a single entry from a cache.
Name | Type | Description |
---|---|---|
catalog | String | Name of the cache defined in the Scoped Caches [sys_scoped_cache] table. |
key | String | Optional. Cache key. Set this parameter to flush a single entry from a cache. |
Type | Description |
---|---|
None |
Example
The following example shows how to flush the "abc" key from a cache named myCache. To flush the entire cache, leave out the key parameter.
ScopedCacheManager – get(String catalog, String key)
Gets a value from a cache.
Name | Type | Description |
---|---|---|
catalog | String | Name of the cache defined in the Scoped Caches [sys_scoped_cache] table. |
key | String | Cache key. |
Type | Description |
---|---|
String | Cache entry. |
Example
The following example shows how to count the number of incident records having short descriptions with a number of characters greater than the key (50). In this case, there are 6 incident records with short descriptions longer than 50 characters. This value is stored in the cache as a reusable string, so you don't have to make a calculation each time you want to retrieve the value.
Output:
ScopedCacheManager – getCacheEntryDetails(String catalog, String key)
Gets cache entry details including byte size, object type, and entry value.
Name | Type | Description |
---|---|---|
catalog | String | Name of the cache defined in the Scoped Caches [sys_scoped_cache] table.
The catalog name must be prefixed with the scope
name and a caret character. For example, "test_cache" in the global scope is
prefixed as |
key | String | Cache key. |
Type | Description |
---|---|
String | String in the format <ObjectType> (<EntrySize>):
<Value.toString()> . |
Example
The following example shows how to display cache entry details for a scoped cache named
test_cache
.
Output:
ScopedCacheManager – prefixFlush(String catalog, String prefix)
Flushes all cache entries that have keys beginning with a specified prefix.
Name | Type | Description |
---|---|---|
catalog | String | Name of the cache defined in the Scoped Caches [sys_scoped_cache] table. |
prefix | String | Prefix by which to search for keys when flushing the cache. |
Type | Description |
---|---|
None |
Example
The following example shows how to flush cache values for keys with the prefix
a
.
Output:
ScopedCacheManager – put(String catalog, String key, String value)
Puts a value in a scoped cache for caches that are Table or Table Column pair types.
Name | Type | Description |
---|---|---|
catalog | String | Name of the cache defined in the Scoped Caches [sys_scoped_cache] table. |
key | String | Cache key. |
value | String | Cache entry. |
Type | Description |
---|---|
None |
Example
The following example shows how to define and retrieve a key called "abc" to a cache named myCache. The cache is table-paired with the Incident [incident] table. The example also shows how the cache is flushed after updating the description field of an incident record.
Output:
ScopedCacheManager – putMultiRow(String catalog, String key, String value, Array ids)
Puts an entry into the cache and sets all records with the specified sys_ids as a flush source for that entry. This method is intended for caches that are Table or Table Column pair types.
Type | Description |
---|---|
None |
Example
The following example shows how to use an incident and user record as flush points. The test_cache key INC0000060 is flushed when either of the specified records is updated.
Output:
ScopedCacheManager – putRow(String catalog, String key, String value, String sysId)
Puts a value in a single row (table) of a cache. Use this method for caches that are Table Row or Table Row and Column pair types.
Type | Description |
---|---|
None |
Example
The following example uses a table row pair cache type named incident_cache. The cache adds the incident caller ID, and the cache entries associated with the changed record's sys_id are cleared.
Output:
On this page
- ScopedCacheManager – flushScopedCache(String catalog, String key)
- ScopedCacheManager – get(String catalog, String key)
- ScopedCacheManager – getCacheEntryDetails(String catalog, String key)
- ScopedCacheManager – prefixFlush(String catalog, String prefix)
- ScopedCacheManager – put(String catalog, String key, String value)
- ScopedCacheManager – putMultiRow(String catalog, String key, String value, Array
ids)
- ScopedCacheManager – putRow(String catalog, String key, String value, String sysId)