Get a cached value for the specified date range and query
966458
def get_cache(self, namespace, query_hash, length, start, end):
        """"""
        query = 'SELECT start, value FROM gauged_cache WHERE namespace = ? ' \
            'AND hash = ? AND length = ? AND start BETWEEN ? AND ?'
        cursor = self.cursor
        cursor.execute(query, (namespace, query_hash, length, start, end))
        return tuple(cursor.fetchall())
297521
public void addQueryDateRange(final String name, final Range<LocalDate> range) {
        if (range.hasLowerBound()) {
            String value = range.lowerEndpoint().toString(QUERY_STRING_DATE_FORMAT);
            addQueryParam(name + ">", value);
        }

        if (range.hasUpperBound()) {
            String value = range.upperEndpoint().toString(QUERY_STRING_DATE_FORMAT);
            addQueryParam(name + "<", value);
        }
    }
1140999
def add_filter_by_date(self, query, out_params):
        
        date_query = formatDateQuery(self.context, 'Requested')
        if date_query:
            query['created'] = date_query
            requested = formatDateParms(self.context, 'Requested')
            out_params.append({'title': _('Requested'),
                               'value': requested,
                               'type': 'text'})
1230857
private V retrieveCachedValue(boolean loadIfExpired, boolean updateStats) {

		V result;
		V oldValue = null;
		Throwable error = null;
		boolean missed = false;

		// race conditions are allowed
		this.approxAccessCounter++;

		long now;

		CachedValue<V> cached = cachedValue; // read the cached value

		if (cached != null) {

			long expiresAt = cached.expiresAt;
			if (expiresAt == Long.MAX_VALUE) {
				updateStats(false, false);
				return cached.value;
			}

			now = U.time();
			if (now <= expiresAt) {
				updateStats(false, false);
				return cached.value;
			}

		} else {
			now = U.time();
		}

		// ----------------- START LOCKS -----------------

		readLock();

		cached = cachedValue; // read the cached value again, inside the read lock

		if (cached == null || now > cached.expiresAt) {

			readUnlock();
			writeLock();

			// double-check: another thread might have acquired write lock and changed state already
			if (cached == null || now > cached.expiresAt) {

				V newValue;

				if (loadIfExpired) {
					try {
						newValue = loader != null ? loader.map(key) : null;

					} catch (Throwable e) {
						error = e;
						newValue = null;
					}

				} else {
					newValue = null;
				}

				oldValue = setValueInsideWriteLock(newValue);

				missed = true;
			}

			// downgrade by acquiring read lock before releasing write lock
			readLock();
			writeUnlock();
		}

		cached = cachedValue;
		result = cached != null ? cached.value : null; // read the cached value

		readUnlock();

		releaseOldValue(oldValue); // release the old value - outside of lock

		if (updateStats) {
			updateStats(missed, error != null);
		}

		if (error != null) {
			throw U.rte("Couldn't recalculate the cache value!", error);
		}

		return result;
	}
422864
def dateDict(date, prefix = ""):
    """"""
    res = {}

    res[prefix+"a"] = date.strftime("%a")
    res[prefix+"A"] = date.strftime("%A")
    res[prefix+"b"] = date.strftime("%b")
    res[prefix+"B"] = date.strftime("%B")
    res[prefix+"c"] = date.strftime("%c")
    res[prefix+"d"] = date.strftime("%d")
    res[prefix+"H"] = date.strftime("%H")
    res[prefix+"I"] = date.strftime("%I")
    res[prefix+"j"] = date.strftime("%j")
    res[prefix+"m"] = date.strftime("%m")
    res[prefix+"M"] = date.strftime("%M")
    res[prefix+"p"] = date.strftime("%p")
    res[prefix+"S"] = date.strftime("%S")
    res[prefix+"U"] = date.strftime("%U")
    res[prefix+"w"] = date.strftime("%w")
    res[prefix+"W"] = date.strftime("%W")
    res[prefix+"x"] = date.strftime("%x")
    res[prefix+"X"] = date.strftime("%X")
    res[prefix+"y"] = date.strftime("%y")
    res[prefix+"Y"] = date.strftime("%Y")
    res[prefix+"Z"] = date.strftime("%Z")

    for i, value in res.items():
        res[i] = locale_to_utf8(value)

    return res
565728
function cacheQuery () {
    // debug
    debug('view:id:collection:get', this.idCacheKey, this.ids)
    // attempt to get from cache
    return this.cache.redis.getAsync(this.idCacheKey)
    // check result
    .then(cached => this.cacheQueryResult(cached))
}
1026623
function cacheQuery () {
    // debug
    debug('id:get', this.idCacheKeys, this.ids)
    // attempt to get from cache
    return this.cache.redis.mgetAsync(this.idCacheKeys)
    // check result
    .then(cached => {
        // list of ids that where not cached
        this.uncachedIds = []
        // check result set for uncached ids
        for (var i=0; i < this.numIds; i++) {
            var cachedValue = undefined
            // decode result if not null
            if (cached[i] !== null) {
                try {
                    // decode JSON
                    cachedValue = JSON.parse(cached[i])
                    // add cached flag
                    cachedValue._cached = true
                }
                catch (err) {
                    // ignore errors
                }
            }
            // if there is cached value use otherwise add id to fetch list
            defined(cachedValue)
                ? this.cached.push(cachedValue)
                : this.uncachedIds.push(this.ids[i])
        }
        // debug
        debug('id:uncachedIds', this.uncachedIds)
        // if all records were cached the return result from cache
        return this.uncachedIds.length === 0
            ? this.cached
            : this.loadUncached()
    })
}
1175925
private static UInteger getCached(long value) {
        if (VALUES != null && value < VALUES.length)
            return VALUES[(int) value];

        return null;
    }
394995
function cacheQueryResult (cached) {
    // decode result if not null
    if (cached !== null) {
        try {
            // decode JSON
            this.cached = JSON.parse(cached)
            // add cached view flag
            this.cached._cachedView = true
        }
        catch (err) {
            // ignore errors
        }
    }
    // return cached result or load
    return defined(this.cached) ? this.cached : this.loadUncached()
}
45228
def query(self, action=None):
        
        if action in self.cache:
            return self.cache[action]['query'].replace('&format=json', '')
        return self.cache.keys() or None
286761
def query_by_expired(cls):
        """"""
        lifetime = current_app.permanent_session_lifetime
        expired_moment = datetime.utcnow() - lifetime
        return cls.query.filter(cls.created < expired_moment)
917297
function(text, options) {
    var execute, queried;
    queried = p.defer();
    // caching disabled unless duration is specified
    options = options != null ? options : {
      duration: 0
    };
    execute = function(params) {
      return db.prepare(text).then(function(stmt) {
        return stmt.execute(params).then(function(results) {
          if (options.duration > 0) {
            cache.store(text, results.rows, options.duration);
          }
          return queried.resolve(results.rows);
        }).done();
      }).done();
    };
    // return results directly if cache hit, run query if cache miss
    cache.get(text).then(function(results) {
      return queried.resolve(results);
    }, function(err) {
      if (err != null) {
        return queried.reject(err);
      } else {
        return execute();
      }
    }).done();
    return queried.promise;
  }
748075
<R> R getValue(TemporalQuery<R> query) {
        R result = temporal.query(query);
        if (result == null && optional == 0) {
            throw new DateTimeException("Unable to extract value: " + temporal.getClass());
        }
        return result;
    }
332979
private DateTime getCachedOnset(final Date date) {
        int index = Arrays.binarySearch(onsetsMillisec, date.getTime());
        if (index >= 0) {
            return onsetsDates[index];
        } else {
            int insertionIndex = -index - 1;
            return onsetsDates[insertionIndex - 1];
        }
    }
1069781
@Route(method= HttpMethod.GET, uri = "/cached")
    @Cached(key="cached", duration = 60)
    public Result cached() {
        String s = DateFormat.getDateTimeInstance().format(new Date());
        return ok(s);
    }
1180782
def get_daterange(self, dataset):
        """"""

        path = '/api/1.0/meta/dataset/{}/daterange'
        return self._api_get(definition.DateRange, path.format(dataset))
366647
def get_cached_value(self, *args, **kwargs):
        
        key = self.get_cache_key(*args, **kwargs)
        logger.debug(key)
        return self.cache.get(key, default=Ellipsis)