def ClearLocks(cacheKey):
    r.delete(cacheKey.getCacheKey('lock_init'))
    r.delete(cacheKey.getCacheKey('lock_mutex'))

    chartCacheKey = CacheKeyGenerator()
    chartCacheKey.set(cacheKey.CounterId, "", cacheKey.WindowSize, cacheKey.ListItemSizeSeconds)

    r.delete(chartCacheKey.getCacheKey('lock_init'))
    r.delete(chartCacheKey.getCacheKey('lock_mutex'))
def UpdateChartCandidate(cacheKey, currentValue):
    chartCacheKey = CacheKeyGenerator()
    chartCacheKey.set(cacheKey.CounterId, "", cacheKey.WindowSize, cacheKey.ListItemSizeSeconds)
    
    chartThreshold = r.get(chartCacheKey.getCacheKey("chartThreshold"))
    if chartThreshold is None:
        chartThreshold = 0
    else:
        chartThreshold = int(chartThreshold)

    logging.debug("chart candidate value: %s, threshold: %s" % (currentValue, chartThreshold))
    if currentValue >= chartThreshold:
        logging.debug("adding chart candidate: %s" % cacheKey.ResourceUri)
        r.sadd(chartCacheKey.getCacheKey("chartCandidates"), cacheKey.ResourceUri)
def ResyncValue(cacheKey):
    totalCacheKey = cacheKey.getCacheKey('total')
    baseValueCacheKey = cacheKey.getCacheKey('baseValue')
    listCacheKey =  cacheKey.getCacheKey('list')
    histListCacheKey =  cacheKey.getCacheKey('historical')
    perfCacheKey = CacheKeyGenerator()
    perfCacheKey.set(cacheKey.CounterId, cacheKey.ResourceUri, cacheKey.WindowSize, 10)
    perfListCacheKey =  perfCacheKey.getCacheKey('historical')
    listSum = r.lrange(listCacheKey, 0, -1)
    totalSum = 0
    for val in listSum:
        totalSum += int(val)
    baseValue = r.get(baseValueCacheKey)
    if baseValue is None:
        baseValue = 0
    else:
        baseValue = int(baseValue)
    r.delete(histListCacheKey)
    r.delete(perfListCacheKey)
    r.set(totalCacheKey, totalSum + baseValue)