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.

Found an issue in documentation? Write to us.

Â