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:
Change the map to a string.
finalMatrix = api.jsonEncode(finalMatrix)
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.
Fetch the string from the shared cache.Â
if(finalMatrices != null){ finalMatrix = api.getSharedCache(tableName) }
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.
Â