Assette allows developers to configure caching for Data Blocks using Redis, which improves performance and reduces the need for repeated queries to data sources. This article explains how to set up and manage caching for both parameterized and non-parameterized Data Blocks.
Overview of Caching in Assette #
When caching is enabled, the result of a Data Block execution is temporarily stored in Redis. If the same request is made again within the configured expiration window, the cached result is returned, bypassing the data source.
Caching supports:
- Faster response times
- Efficient reuse of frequently requested data
- Reduced load on external systems
Required Configuration #
RedisCachingSettings Block #
Property | Value |
---|---|
Name | RedisCachingSettings |
Output Type | Setting |
Block Type | Setting |
This block defines the Redis connection configuration and must be properly set after DevOps provisions the caching infrastructure. A security key should also be added to the Key Vault using the Developer Tools application.
Definition:
{
"host": "<clientID>-redis-qa.redis.cache.windows.net",
"port": "6380",
"password": "$SECRET:RedisCachingSecret",
"isssl": "true"
}
Note: Replace
<clientID>
with your actual client identifier.
Example: Caching Without Parameters #
AccountMaster_Caching #
Property | Value |
---|---|
Name | AccountMaster_Caching |
Output Type | Data table |
Block Type | Caching |
This block caches the output of the AccountMaster
block without any parameters. Every run returns the same cached result for the duration defined by expiryminutes
.
Definition:
{
"block": "AccountMaster",
"expiryminutes": "1",
"keytemplate": "AccountMaster_Caching_Testing"
}
Example: Caching With Parameters #
AccountMaster_CachingWithParam #
Property | Value |
---|---|
Name | AccountMaster_CachingWithParam |
Output Type | Data table |
Block Type | Caching |
This block demonstrates parameter-sensitive caching. Each unique combination of parameter values results in a separate cache entry.
Definition:
{
"block": "AccountMaster",
"expiryminutes": "1",
"keytemplate": "AccountMaster_Caching_code:{{Code}}_Strategy:{{Strategy}}"
}
- The placeholders
{{Code}}
and{{Strategy}}
will be dynamically replaced with the actual parameter values during runtime. - Repeating the same parameter combination fetches the cached result.
- A different combination creates a new cache entry.
Setting the Cache Expiry #
The expiryminutes
field specifies the number of minutes the cached result is valid. You may configure this to values such as 1
, 5
, or 10
minutes depending on how often the data changes.
How Cached Data is Handled by the Assette #
Initial Data Block Execution #
When a Data Object or presentation requests data from a Data Block (e.g., AccountMaster_Caching or AccountMaster_CachingWithParam), the following steps occur:
- The system checks if caching is enabled for the Data Block.
- If enabled, it reads the keytemplate from the block’s caching definition to construct a unique cache key.
- For example:
- AccountMaster_Caching_Testing for a non-parameterized block.
- AccountMaster_Caching_code:123_Strategy:Equity for a parameterized block.
- For example:
Redis Cache Lookup #
- The system uses the constructed cache key to check Redis for a stored result.
- If a matching key exists and the cache entry is still valid (i.e., within
expiryminutes
):- The system retrieves the cached data from Redis.
- This data is returned immediately to the requesting layer (e.g., Smart Page, Smart Table, or PPTX), skipping the Data Block execution.
- This improves performance and reduces load on the data source.
Cache Miss or Expired Entry #
- If the key does not exist in Redis (first-time run, new parameters, or expired cache):
- The system executes the original Data Block logic as normal (e.g., SQL query, API call).
- The resulting data is then:
- Returned to the user
- Stored in Redis using the same key, along with the specified expiry time.
Expiry Management #
- The expiryminutes setting determines how long each entry stays in the cache.
- After expiration, the entry is removed from Redis, and the next request will re-run the block and repopulate the cache.
Key Behaviors #
Action | System Behavior |
---|---|
First run with parameters | Executes block, stores result in Redis using parameterized key |
Repeat run with same parameters | Retrieves cached result directly from Redis |
Run with different parameters | Generates a new key and caches that result separately |
Cache expired | Executes block again and refreshes Redis with new data |