Package httpcache. October 17, 2017

Similar documents
Package cattonum. R topics documented: May 2, Type Package Version Title Encode Categorical Features

Package virustotal. May 1, 2017

Package fastdummies. January 8, 2018

Package robotstxt. November 12, 2017

Package opencage. January 16, 2018

Package bigqueryr. October 23, 2017

Package fitbitscraper

Package calpassapi. August 25, 2018

Package dkanr. July 12, 2018

Package censusr. R topics documented: June 14, Type Package Title Collect Data from the Census API Version 0.0.

Package censusapi. August 19, 2018

Package smapr. October 20, 2017

Package lumberjack. R topics documented: July 20, 2018

Package facerec. May 14, 2018

Package BiocManager. November 13, 2018

Package rwars. January 14, 2017

Package internetarchive

Package redux. May 31, 2018

Package validara. October 19, 2017

Package ECctmc. May 1, 2018

Package datasets.load

Package ezknitr. September 16, 2016

Package repec. August 31, 2018

Package taxizedb. June 21, 2017

Package goodpractice

Package bigqueryr. June 8, 2018

Package rbraries. April 18, 2018

Package SEMrushR. November 3, 2018

Package simplecache. August 22, 2017

Package routr. October 26, 2017

Package keyholder. May 19, 2018

Package barcoder. October 26, 2018

Package githubinstall

Package patentsview. July 12, 2017

Package cancensus. February 4, 2018

Package rzeit2. January 7, 2019

Package algorithmia. September 13, 2016

Package pdfsearch. July 10, 2018

Package shinyfeedback

Package loggit. April 9, 2018

Package reconstructr

Package canvasxpress

Package textrank. December 18, 2017

Package postgistools

Package geojsonsf. R topics documented: January 11, Type Package Title GeoJSON to Simple Feature Converter Version 1.3.

Package memoise. April 21, 2017

Package gtrendsr. October 19, 2017

Package sqliter. August 29, 2016

Package aws.transcribe

Package data.world. April 5, 2018

Package widyr. August 14, 2017

Package gtrendsr. August 4, 2018

Package ggimage. R topics documented: November 1, Title Use Image in 'ggplot2' Version 0.0.7

Package pkgbuild. October 16, 2018

Package rcmdcheck. R topics documented: November 10, 2018

Package SASmarkdown. R topics documented: November 30, Version Date Title 'SAS' Markdown

Package knitrprogressbar

Package carbonate. R topics documented: October 14, 2018

Package rnaturalearth

Package darksky. September 20, 2017

Package pangaear. January 3, 2018

Package catchr. R topics documented: December 30, Type Package. Title Catch, Collect, and Raise Conditions. Version 0.1.0

Package editdata. October 7, 2017

Package promote. November 15, 2017

Package rgho. R topics documented: January 18, 2017

Package clipr. June 23, 2018

Package ggimage. R topics documented: December 5, Title Use Image in 'ggplot2' Version 0.1.0

Package shinyhelper. June 21, 2018

Package GetITRData. October 22, 2017

Package humanize. R topics documented: April 4, Version Title Create Values for Human Consumption

Package messaging. May 27, 2018

Package RODBCext. July 31, 2017

Package desc. May 1, 2018

Package oec. R topics documented: May 11, Type Package

Package jdx. R topics documented: January 9, Type Package Title 'Java' Data Exchange for 'R' and 'rjava'

Package nodbi. August 1, 2018

Package htmlwidgets. July 10, 2017

Package reval. May 26, 2015

Package nlgeocoder. October 8, 2018

Package condusco. November 8, 2017

Package spelling. December 18, 2017

Package spark. July 21, 2017

Package rgdax. January 7, 2019

Package getopt. February 16, 2018

Package WikipediR. February 5, 2017

Package rprojroot. January 3, Title Finding Files in Project Subdirectories Version 1.3-2

Package profvis. R topics documented:

Package wikitaxa. December 21, 2017

Package rdryad. June 18, 2018

Package statsdk. September 30, 2017

Package googleauthr. November 14, 2017

Package labelvector. July 28, 2018

Package datapasta. January 24, 2018

Package farver. November 20, 2018

Package semver. January 6, 2017

Package rtext. January 23, 2019

Package mdftracks. February 6, 2017

Package triebeard. August 29, 2016

Package liftr. R topics documented: May 14, Type Package

Package kirby21.base

Transcription:

Package httpcache October 17, 2017 Type Package Title Query Cache for HTTP Clients In order to improve performance for HTTP API clients, 'httpcache' provides simple tools for caching and invalidating cache. It includes the HTTP verb functions GET, PUT, PATCH, POST, and DELETE, which are drop-in replacements for those in the 'httr' package. These functions are cache-aware and provide default settings for cache invalidation suitable for RESTful APIs; the package also enables custom cache-management strategies. Finally, 'httpcache' includes a basic logging framework to facilitate the measurement of HTTP request time and cache performance. Version 1.1.0 URL http://enpiar.com/r/httpcache, https://github.com/nealrichardson/httpcache BugReports https://github.com/nealrichardson/httpcache/issues License MIT + file LICENSE Depends R (>= 3.0.0) Imports digest, httr (>= 1.0.0), utils Suggests httptest, knitr RoxygenNote 6.0.1 VignetteBuilder knitr NeedsCompilation no Author Neal Richardson [aut, cre] Maintainer Neal Richardson <neal.p.richardson@gmail.com> Repository CRAN Date/Publication 2017-10-17 21:31:30 UTC 1

2 buildcachekey R topics documented: buildcachekey....................................... 2 cache-api.......................................... 3 cache-management..................................... 3 cached-http-verbs...................................... 4 cachedpost........................................ 5 cachelogsummary..................................... 5 dropcache.......................................... 6 halt............................................. 6 loadlogfile......................................... 7 logmessage......................................... 7 requestlogsummary.................................... 8 savecache.......................................... 8 startlog........................................... 9 uncached.......................................... 9 Index 11 buildcachekey Construct a unique cache key for a request This function encapsulates the logic of making a cache key, allowing other code or libraries to access the HTTP cache programatically. buildcachekey(url, query = NULL, body = NULL, extras = c()) url query body extras character request URL Optional query parameters for the request Optional request body character Optional additional annotations to include in the cache key. Character value, starting with url and including hashed query and body values if provided, to be used as the cache key for this request.

cache-api 3 cache-api HTTP Cache API These functions provide access to what s stored in the cache. hitcache(key) getcache(key) setcache(key, value) key value character, typically a URL or similar For setcache, an R object to set in the cache for key. hitcache returns logical whether key exists in the cache. getcache returns the value stored in the cache, or NULL if there is nothing cached. setcache is called for its side effects. cache-management Manage the HTTP cache These functions turn the cache on and off and clear the contents of the query cache. cacheon() cacheoff() clearcache() Nothing. Functions are run for their side effects.

4 cached-http-verbs cached-http-verbs Cache-aware versions of httr verbs These functions set, read from, and bust the HTTP query cache. They wrap the similarly named functions in the httr package and can be used as drop-in replacements for them. GET(url,...) PUT(url,..., drop = dropcache(url)) POST(url,..., drop = droponly(url)) PATCH(url,..., drop = dropcache(url)) DELETE(url,..., drop = dropcache(url)) url character URL of the request... additional arguments passed to the httr functions drop For PUT, PATCH, POST, and DELETE, code to be executed after the request. This is intended to be for supplying cache-invalidation logic. By default, POST drops cache only for the specified url (i.e. droponly()), while the other verbs drop cache for the request URL and for any URLs nested below it (i.e. dropcache()). Details GET checks the cache before making an HTTP request, and if there is a cache miss, it sets the response from the request into the cache for future requests. The other verbs, assuming a more or less RESTful API, would be assumed to modify server state, and thus they should trigger cache invalidation. They have default cache-invalidation strategies, but you can override them as desired. The corresponding httr response object, potentially read from cache See Also dropcache() cachedpost()

cachedpost 5 cachedpost Cache the response of a POST Some APIs have resources where a POST is used to send a command that returns content and doesn t modify state. In this case, it s more like a GET. This may occur where one might normally GET but the request URI would be too long for the server to accept. cachedpost thus behaves more like GET, checking for a cached response before performing the request and setting cache if the request is successful. It does no cache dropping, unlike httpcache::post(). cachedpost(url,...) url character URL of the request... additional arguments passed to the httr functions The corresponding httr response object, potentially read from cache cachelogsummary Summarize cache performance from a log Summarize cache performance from a log cachelogsummary(logdf) logdf A logging data.frame, as loaded by loadlogfile(). A list containing counts of cache hit/set/drop events, plus a cache hit rate.

6 halt dropcache Invalidate cache These functions let you control cache invalidation. droponly invalidates cache only for the specified URL. droppattern uses regular expression matching to invalidate cache. dropcache is a convenience wrapper around droppattern that invalidates cache for any resources that start with the given URL. dropcache(x) droponly(x) droppattern(x) x character URL or regular expression Nothing. Functions are run for their side effects. halt Stop, log, and no call Wrapper around base::stop() that logs the error message and then stops with call.=false by default. halt(..., call. = FALSE)... arguments passed to stop call. Nothing. Raises an error. logical: print the call? Default is FALSE, unlike stop

loadlogfile 7 loadlogfile Read in a httpcache log file Read in a httpcache log file loadlogfile(filename, scope = c("cache", "HTTP")) filename scope character name of the log file, passed to utils::read.delim() character optional means of selecting only certain log messages. By default, only "CACHE" and "HTTP" log messages are kept. Other logged messages, such as "ERROR" messages from halt(), will be dropped from the resulting data.frame. A data.frame of log results. logmessage Log a message Log a message logmessage(...)... Strings to pass to base::cat() Nothing

8 savecache requestlogsummary Summarize HTTP requests from a log Summarize HTTP requests from a log requestlogsummary(logdf) logdf A logging data.frame, as loaded by loadlogfile(). A list containing counts of HTTP requests by verb, as well as summaries of time spent waiting on HTTP requests. savecache Save and load cache state Warm your query cache from a previous session by saving out the cache and loading it back in. savecache(file) loadcache(file) file character file path to write the cache data to, in.rds format Nothing; called for side effects.

startlog 9 startlog Enable logging Enable logging startlog(filename = "", append = FALSE) filename append character: a filename/path where the log can be written out. If "", messages will print to stdout (the screen). See base::cat(). logical: if the file already exists, append to it? Default is FALSE, and if not in append mode, if the filename exists, it will be deleted. Nothing. uncached Context manager to temporarily turn cache off if it is on If you don t want to store the response of a GET request in the cache, wrap it in uncached(). It will neither read from nor write to cache. uncached(...) Details... Things to evaluate with caching off uncached will not invalidate cache records, if present. It only ignores them. Whatever... returns.

10 uncached Examples uncached(get("http://httpbin.org/get"))

Index base::cat(), 7, 9 base::stop(), 6 buildcachekey, 2 cache-api, 3 cache-management, 3 cached-http-verbs, 4 cachedpost, 5 cachedpost(), 4 cachelogsummary, 5 cacheoff (cache-management), 3 cacheon (cache-management), 3 clearcache (cache-management), 3 setcache (cache-api), 3 startlog, 9 uncached, 9 utils::read.delim(), 7 DELETE (cached-http-verbs), 4 dropcache, 6 dropcache(), 4 droponly (dropcache), 6 droponly(), 4 droppattern (dropcache), 6 GET (cached-http-verbs), 4 getcache (cache-api), 3 halt, 6 halt(), 7 hitcache (cache-api), 3 httpcache::post(), 5 loadcache (savecache), 8 loadlogfile, 7 loadlogfile(), 5, 8 logmessage, 7 PATCH (cached-http-verbs), 4 POST (cached-http-verbs), 4 PUT (cached-http-verbs), 4 requestlogsummary, 8 savecache, 8 11