'What is the expiry of property we set using d Properties.setProperty(key, value) method of Class PropertiesService

I am unable to find what is the expiry of property we set using Properties.setProperty(key, value) method of Class PropertiesService. I know we can delete it using deleteProperty(key).

example: var userProperties = PropertiesService.getUserProperties(); userProperties.setProperty('userEmail', "user@xyz.com");

When the value of userEmail will be removed from the storage if we don't delete it using deleteProperty(key) method?



Solution 1:[1]

In the current state there does not appear to be an Expiration Time property within the Service Properties, this would need to be set manually. Something like this:

const EXPIRY_TIME_KEY = "expiryTime"
const HAS_ACCESS_KEY = "hasAcces"
const userProperties = PropertiesService.getUserProperties()

function isExpired() {
  const expProp = userProperties.getProperty(EXPIRY_TIME_KEY)
  const checkerTimer = (new Date().getTime() - expProp) / 1000
  /* 1 hour timer */
  if(checkerTimer > 3600){
    userProperties.setProperty(HAS_ACCESS_KEY, false)
  }
}

function grantAcces() {
  userProperties.setProperty(EXPIRY_TIME_KEY, new Date().getTime())
  userProperties.setProperty(HAS_ACCESS_KEY, true)
}

If you want to add this functionality to Google Apps Script, you can make a feature request using this template.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1