12

Does anybody know what the maximum expiration time for Cache Services in Google Apps Script is? I am running my script on Google Sites and have tried to run a trigger that re-caches the cache, but the cache seems to still expire overnight and I am not certain how long it lasts. If anyone has timed the actual length of the cache it would be good to know - unfortunately, Google hasn't made this info public.

Eric Koleda
  • 12,420
  • 1
  • 33
  • 51
tiampen
  • 121
  • 4

1 Answers1

16

We are working on adding that information to our documentation, but the maximum time something can be stored in the cache in 6 hours (21600 seconds) and the default time is 10 minutes (600 seconds).

Eric Koleda
  • 12,420
  • 1
  • 33
  • 51
  • Ah. I was trying to cache something for 24 hours. Would you recommend writing this data to a google sheet instead of caching it? – Dustin Michels Sep 04 '18 at 17:56
  • 2
    You may want to look into using the PropertiesService, which can be used to store key-value data indefinitely. – Eric Koleda Sep 19 '18 at 14:17
  • @EricKoleda have you managed to add that information to your documentation after 10 years :) ? Seriously, how to set the cache timeout? Thanks – ACV Mar 28 '22 at 16:30
  • @EricKoleda found the answer, yes the documentation is updated: `expirationInSeconds Integer the maximum time the value remains in the cache, in seconds. The minimum is 1 second and the maximum is 21600 seconds (6 hours).` https://developers.google.com/apps-script/reference/cache/cache#put(String,String,Integer) thanks – ACV Mar 28 '22 at 16:56
  • @EricKoleda please consider updating your answer with that hint towards [PropertiesService](https://developers.google.com/apps-script/reference/properties/properties-service) - unless there is some catch, it seems like the perfect answer for a non-expiring caching solution. Exactly what I was looking for, thanks! – alex_jwb90 Jun 28 '23 at 15:13