/
How to use shared cache

How to use shared cache

Question

I want to store matrices in the shared cache. It looks like I have an issue with fetching them.

I do the following:

  1. Change the map to a string.

    finalMatrix = api.jsonEncode(finalMatrix)
  2. Store the string with the tableName.

    def tableName = (configSister + ":" + hwg).toString() finalMatrices = api.setSharedCache(tableName, finalMatrix) // The shared cache key size should not exceed 10k bytes.
  3. Fetch the string from the shared cache. 

    if(finalMatrices != null){ finalMatrix = api.getSharedCache(tableName) }
  4. Change the string to a map again.

With changing it back to a map I think there is a problem. If I want to fetch a specific line from it afterwards with finalMatrix.findRow("Product ID", productId) it breaks.

Also, are there any recommendations regarding releasing of the cache? Shall I use api.releaseSharedCache(...)? Should I care about it or let it be not handled?

Answer

The reason why finalMatrix.findRow("Product ID", productId) doesn't work is that you encoded ResultMatrix to a string (api.jsonEncode(finalMatrix)) and it was decoded back to a map (api.jsonDecode(finalMatrix)).

So use a map instead and it will work.

The cache expires 15 minutes after the last access.

Related content

Caching Strategies in Configuration
Caching Strategies in Configuration
More like this
Performance Improvements (Batching, api.getBatchInfo)
Performance Improvements (Batching, api.getBatchInfo)
More like this
How to Set Logic Based Customer Input Filter
How to Set Logic Based Customer Input Filter
Read with this

Found an issue in documentation? Write to us.