See all keys for Google Script cache

Viewed 503

The Google Script Cache object has methods for getting a particular key or a list of keys, but is there any way to simply see all the keys currently stored in the cache?

1 Answers

If there were, it would be documented. It isn't necessary though, since cache misses are normal and expected behavior.

The assumed behavior for caches is that you can get the value from elsewhere if you don't have it in cache. So you first try to get it from cache, and if it isn't there, you just get null. If your cache try returns null, then you get it the other way:

var possibleValue = myCache.get("some key");
if (possibleValue === null) {
  possibleValue = computeValueForKey("some key");
  myCache.put("some key", possibleValue, numSeconds);
}
// Use `possibleValue`, since we got it, somehow.

If you are using a cache but don't know the keys, you need to change your application design.

Related