Get's cache response if any
495009
public function getCachedResult($interval)
    {
        if (!empty(self::$resultCache[$interval])) {
            return self::$resultCache[$interval];
        }
        return false;
    }
241158
def apply_caching(response):
    """"""
    for k, v in config.get('HTTP_HEADERS').items():
        response.headers[k] = v
    return response
520171
def _get_from_cache(self, sector, scale, eft, basis):
        """"""
        try:
            return self._cache[eft][scale][basis][sector]
        except KeyError:
            return None
621557
function process_get(request, response, uri) {
	// if path is /things then return the set of thing models
	let path = URL.parse(request.url).pathname;
	
	if (path === "/things") {
		if (!authorised(request))
			return fail(401, "unauthorized", response);
		
		let list = [];
		
		for (var name in things) {
			if (things.hasOwnProperty(name)) {
				list.push(things[name].model);
			}
		}
		
		body = JSON.stringify(list, null, 4);
	
		response.writeHead(200, {
			'Content-Type': mime_types.json,
			'Pragma': 'no-cache',
			'Cache-Control': 'no-cache',
			'Access-Control-Allow-Origin': '*',
			'Access-Control-Allow-Credentials': 'true',
			'Content-Length': body.length
		});

		if (request.method === "GET")
				response.write(body);

		response.end();
		return;
	}

	// does path start with /things/thingID for some thingID?

	if (/^\/things\/.+/.test(path)) {
		if (!authorised(request))
			return fail(401, "unauthorized", response);

		path = path.substr(8);
		
		let i = path.indexOf('/');
		var thingID, body;
		
		if (i < 0) {
			thingID = path;
			path = "";
		} else {
			thingID = path.substr(0, i);
			path = path.substr(i);
		}
		
		if (thingID) {
			let thing = things[thingID];
			
			if (!thing)
				return fail(404, "unknown thing: " + thingID, response);
				
			if (!thing.model)
				return fail(404, "no model for thing: " + thingID, response);
				
			if (path === "") {
				body = JSON.stringify(thing.model, null, 4);
				console.log(body);
			} else if (path === "/properties"){
				// construct set of property values
				let values = {};
				
				for (var name in thing.properties) {
					if (thing.properties.hasOwnProperty(name)) {
						values[name] = thing.properties[name].value;
					}
				}
				
				body = JSON.stringify(values, null, 4);
			} else if (/^\/properties\/.+/.test(path)) {
				path = path.substr(12);
				console.log("property name: " + path);
				let property = thing.properties[path];
				
				if (property === undefined)
					return fail(404, "unknown property: " + path, response);
					
				body = JSON.stringify(property.value, null, 4);
			} else if (path === "/events") {
				// add to thing's set of server-sent event streams
				console.log("new server-sent event stream for thing: " + thing.name);
				
				response.writeHead(200, {
					'Content-Type': 'text/event-stream',
					'Cache-Control': 'no-cache',
					'Connection': 'keep-alive',
					'Access-Control-Allow-Credentials': 'true',
					'Access-Control-Allow-Origin': '*'
				});

				if (request.method === "HEAD") {
					response.end();
					return;
				}

				let id = gensym();
				console.log('client id = ' + id);
				
				thing.clients[id] = {
					id: id,
					response: response
				};
				
				// tidy up when connection is closed
				// e.g. after a browser tab is hidden

				response.on("close", function () {
					console.log('lost client id = ' + id);
					let clients = thing.clients
					delete clients[id];
				});

				response.on("end", function () {
					console.log('lost client id = ' + id);
					let clients = thing.clients
					delete clients[id];
				});

				return;
			} else if (/^\/events\/.+/.test(path)) {
				path = path.substr(8);
				console.log("long poll on event named: " + path);
				let event = thing.events[path];
				
				if (event === undefined)
					return fail(404, "unknown event: " + path, response);
					
				event.longpoll.push(response);
				return;
			} else {
				return fail(404, "invalid request: " + uri, response);
			}
			
			console.log('body length = ' + body.length);
			
			response.writeHead(200, {
				'Content-Type': mime_types.json,
				'Pragma': 'no-cache',
				'Cache-Control': 'no-cache',
				'Access-Control-Allow-Origin': '*',
				'Access-Control-Allow-Credentials': 'true',
				'Content-Length': body.length
			});

			if (request.method === "GET")
					response.write(body);

			response.end();
			return;
		}
		
		return fail(404, "missing thingID: " + path, response);
	}
	
	let prefix = './www';

	console.log('request for "' + path + '"');
	// assume this is a request for a file

	if (path[path.length-1] === '/')
		path += 'index.html';

	let filename = decodeURI(prefix + path);
	let gzipped = false;

	console.log('filename: ' + filename);

	FS.stat(filename, function(error, stat) {
		var ext = PATH.extname(filename);
		var mime = null;

		if (ext === ".gz") {
			gzipped = true;
			ext = PATH.extname(filename.substr(0, filename.length-3));
		}

		if (ext.length > 1)
			mime = mime_types[ext.split(".")[1]];

		if (error || !mime) {
			console.log("unable to serve " + filename);
			var body = "404 not found: " + request.url;
			response.writeHead(404, {
				'Content-Type': 'text/plain',
				'Content-Length': body.length
			});

			if (request.method === "GET")
				response.write(body);

			response.end();
		} else {
			if (gzipped) {
				console.log("filename has mime type " + mime);
				response.writeHead(200, {
					'Content-Type': mime,
					'Content-Encoding': 'gzip',
					'Pragma': 'no-cache',
					'Cache-Control': 'no-cache',
					'Access-Control-Allow-Origin': '*',
					'Access-Control-Allow-Credentials': 'true',
					'Content-Length': stat.size
				});
			} else {
				response.writeHead(200, {
					'Content-Type': mime,
					'Pragma': 'no-cache',
					'Cache-Control': 'no-cache',
					'Access-Control-Allow-Origin': '*',
					'Access-Control-Allow-Credentials': 'true',
					'Content-Length': stat.size
				});
			}

			if (request.method === "GET") {
				var stream = FS.createReadStream(filename);
				stream.pipe(response);
			} else
				response.end();
		}
	});
}
468226
def request(params, &block)
      cached_token = check_cache(request_params(params))
      return cached_token if cached_token
      cache_response(request_no_cache(request_params(params), &block))
    end
929551
def _get(self, url, params=None, headers=None):
        """"""
        url = self.clean_url(url)
        response = requests.get(url, params=params, verify=self.verify,
                                timeout=self.timeout, headers=headers)
        return response
921631
def _get_json(self, url):
        
        self.log.info(u"/GET " + url)
        r = requests.get(url)
        if hasattr(r, 'from_cache'):
            if r.from_cache:
                self.log.info("(from cache)")
        if r.status_code != 200:
            throw_request_err(r)

        return r.json()
101282
def get_cached(self, link, default=None):
        ''''''
        if hasattr(link, 'uri'):
            return self.id_map.get(link.uri, default)
        else:
            return self.id_map.get(link, default)
757967
def execute(self, ignore_cache=False):
        
        if ignore_cache or not hasattr(self, '_response'):
            es = connections.get_connection(self._using)

            self._response = self._response_class(
                self,
                es.search(
                    index=self._index,
                    body=self.to_dict(),
                    **self._params
                )
            )
        return self._response
1272580
def has_uncacheable_headers(self, response):
        

        cc_dict = get_header_dict(response, 'Cache-Control')
        if cc_dict:
            if 'max-age' in cc_dict and cc_dict['max-age'] == '0':
                return True
            if 'no-cache' in cc_dict:
                return True
            if 'private' in cc_dict:
                return True
        if response.has_header('Expires'):
            if parse_http_date(response['Expires']) < time.time():
                return True
        return False
785538
def _get(self, action, show, proxy, timeout):
        
        silent = self.flags['silent']

        if action in self.cache:
            if action != 'imageinfo' and action != 'labels':
                utils.stderr("+ %s results in cache" % action, silent)
                return
        else:
            self.cache[action] = {}

        if self.flags.get('skip') and action in self.flags['skip']:
            if not self.flags['silent']:
                utils.stderr("+ skipping %s" % action)
            return

        if 'requests' not in self.data:
            self.data['requests'] = []

        if len(self.data['requests']) >= self.REQUEST_LIMIT:
            raise StopIteration("Hit REQUEST_LIMIT = %d" % self.REQUEST_LIMIT)

        if self.data['requests'] and self.REQUEST_DELAY:
            utils.stderr("REQUEST_DELAY = %d seconds" % self.REQUEST_DELAY)
            sleep(self.REQUEST_DELAY)

        # make the request
        qobj = WPToolsQuery(lang=self.params['lang'],
                            variant=self.params.get('variant'),
                            wiki=self.params.get('wiki'),
                            endpoint=self.params.get('endpoint'))
        qstr = self._query(action, qobj)
        req = self._request(proxy, timeout)
        response = req.get(qstr, qobj.status)

        self.cache[action]['query'] = qstr
        self.cache[action]['response'] = response
        self.cache[action]['info'] = req.info

        self.data['requests'].append(action)

        self._set_data(action)

        if show and not self.flags.get('silent'):
            self.show()
1321609
function checkCache (config, pattern) {
	if (!useCache(config)) {
		return RESPONSE_UNKNOWN;
	}

	const valueRetrieved = kvGet(config, pattern);
	if (valueRetrieved === RESPONSE_UNKNOWN) {
		return RESPONSE_UNKNOWN;
	}
	/* Check if the cache entry has expired. */
	const lastValidDate = new Date(valueRetrieved.validUntil);
	if (lastValidDate <= Date.now()) {
		/* The cache entry has expired. */
		return RESPONSE_UNKNOWN;
	}
	return valueRetrieved.response;
}
200892
def _get_cached(self):
        """"""
        lines = self.context.cachedstr[self.icached[0]:self.icached[1]]
        return self._get_statements(lines, self.icached[0])
560317
def process_response(self, request, response):
        """"""

        # never cache headers + ETag
        add_never_cache_headers(response)

        if not hasattr(request, '_cache_update_cache') or not request._cache_update_cache:
            # We don't need to update the cache, just return.
            return response
        if request.method != 'GET':
            # This is a stronger requirement than above. It is needed
            # because of interactions between this middleware and the
            # HTTPMiddleware, which throws the body of a HEAD-request
            # away before this middleware gets a chance to cache it.
            return response
        if not response.status_code == 200:
            return response

        # use the precomputed cache_key
        if request._cache_middleware_key:
            cache_key = request._cache_middleware_key
        else:
            cache_key = learn_cache_key(request, response, self.cache_timeout, self.key_prefix)

        # include the orig_time information within the cache
        cache.set(cache_key, (time.time(), response), self.cache_timeout)
        return response
237247
def cached(func):
    """"""
    ret = None

    def call_or_cache(*args, **kwargs):
        nonlocal ret
        if ret is None:
            ret = func(*args, **kwargs)
        return ret

    return call_or_cache
594696
def __retrieve(self, key):
        ''' 
        '''
        with self.get_conn() as conn:
            try:
                c = conn.cursor()
                if key is None:
                    c.execute("SELECT value FROM cache_entries WHERE key IS NULL")
                else:
                    c.execute("SELECT value FROM cache_entries WHERE key = ?", (key,))
                result = c.fetchone()
                if result is None or len(result) != 1:
                    getLogger().info("There's no entry with key={key}".format(key=key))
                    return None
                else:
                    return result[0]
            except:
                getLogger().exception("Cannot retrieve")
                return None
243595
def cache_response(self, request, response, body=None, status_codes=None):
        
        # From httplib2: Don't cache 206's since we aren't going to
        #                handle byte range requests
        cacheable_status_codes = status_codes or self.cacheable_status_codes
        if response.status not in cacheable_status_codes:
            logger.debug(
                "Status code %s not in %s", response.status, cacheable_status_codes
            )
            return

        response_headers = CaseInsensitiveDict(response.headers)

        # If we've been given a body, our response has a Content-Length, that
        # Content-Length is valid then we can check to see if the body we've
        # been given matches the expected size, and if it doesn't we'll just
        # skip trying to cache it.
        if (
            body is not None
            and "content-length" in response_headers
            and response_headers["content-length"].isdigit()
            and int(response_headers["content-length"]) != len(body)
        ):
            return

        cc_req = self.parse_cache_control(request.headers)
        cc = self.parse_cache_control(response_headers)

        cache_url = self.cache_url(request.url)
        logger.debug('Updating cache with response from "%s"', cache_url)

        # Delete it from the cache if we happen to have it stored there
        no_store = False
        if "no-store" in cc:
            no_store = True
            logger.debug('Response header has "no-store"')
        if "no-store" in cc_req:
            no_store = True
            logger.debug('Request header has "no-store"')
        if no_store and self.cache.get(cache_url):
            logger.debug('Purging existing cache entry to honor "no-store"')
            self.cache.delete(cache_url)
        if no_store:
            return

        # If we've been given an etag, then keep the response
        if self.cache_etags and "etag" in response_headers:
            logger.debug("Caching due to etag")
            self.cache.set(
                cache_url, self.serializer.dumps(request, response, body=body)
            )

        # Add to the cache any 301s. We do this before looking that
        # the Date headers.
        elif response.status == 301:
            logger.debug("Caching permanant redirect")
            self.cache.set(cache_url, self.serializer.dumps(request, response))

        # Add to the cache if the response headers demand it. If there
        # is no date header then we can't do anything about expiring
        # the cache.
        elif "date" in response_headers:
            # cache when there is a max-age > 0
            if "max-age" in cc and cc["max-age"] > 0:
                logger.debug("Caching b/c date exists and max-age > 0")
                self.cache.set(
                    cache_url, self.serializer.dumps(request, response, body=body)
                )

            # If the request can expire, it means we should cache it
            # in the meantime.
            elif "expires" in response_headers:
                if response_headers["expires"]:
                    logger.debug("Caching b/c of expires header")
                    self.cache.set(
                        cache_url, self.serializer.dumps(request, response, body=body)
                    )