def stateIsInCache()

in cloud-run-alwayson-cpu-weather-advisory/python/main.py [0:0]


def stateIsInCache(state):
    'check if state alerts are in cache & "fresh"'
    useCache = False
    fma = time() - 15*MINUTE  # "15 minutes ago"
    stateData = getStateFromCache(state)
    if stateData:
        ts = stateData['lastUpdate']
        lastUpdate = ts.timestamp() if hasattr(ts, 'timestamp') \
                else mktime(ts.timetuple())
        useCache = lastUpdate > fma
    print(('** Cache fresh, use in-cache data (%s)' if useCache \
            else '** Cache stale/missing, API fetch (%s)') % state)
    return useCache