foo: Example function with caching.

Description Usage Arguments Examples

Description

Example function with caching.

Usage

1
  foo(doi, apikey, cache = FALSE, backend = "local")

Arguments

doi

Logical

key

API key

cache

Logical, defaults to FALSE

backend

One of local, redis, couchdb, mongodb, sqlite.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Get some DOIs via rplos
dois <- searchplos(terms="*:*", fields='id', toquery='doc_type:full', limit=25)
dois <- do.call(c, dois[,1])

# Using local storage
foo(doi = dois, apikey="WQcDSXml2VSWx3P")

# Using local storage, the default, 1st run with cache=TRUE same as cache=FALSE, then 2nd time faster
system.time( foo(doi = dois, apikey="WQcDSXml2VSWx3P", cache=FALSE) )
system.time( foo(doi = dois, apikey="WQcDSXml2VSWx3P", cache=TRUE) )
system.time( foo(doi = dois, apikey="WQcDSXml2VSWx3P", cache=TRUE) )

# Using redis, redis should be a little bit faster
system.time( foo(doi = dois, apikey="WQcDSXml2VSWx3P") )
system.time( foo(doi = dois, apikey="WQcDSXml2VSWx3P", cache=TRUE, backend="sqlite") )
system.time( foo(doi = dois, apikey="WQcDSXml2VSWx3P", cache=TRUE, backend="sqlite") )

# Using sqlite, quite a bit slower than local and redis
dbCreate("mydb", type = "SQLite")
db <- dbInit("mydb", type = "SQLite")
system.time( foo(doi = dois, apikey="WQcDSXml2VSWx3P") )
system.time( foo(doi = dois, apikey="WQcDSXml2VSWx3P", cache=TRUE, backend="sqlite") )
system.time( foo(doi = dois, apikey="WQcDSXml2VSWx3P", cache=TRUE, backend="sqlite") )

sckott/cachecall documentation built on May 29, 2019, 3:46 p.m.