Static Value Storage
The library has support for storing and retrieving static values, functionality that can be used to work with API credentials or cache query results.
Qualified Name | Type | Release |
---|---|---|
- returns statically stored value from config (apoc.static.<key>) or server lifetime storage |
|
|
- returns statically stored values from config (apoc.static.<prefix>.*) or server lifetime storage |
|
|
- stores value under key for server lifetime storage, returns previously stored or configured value |
|
|
apoc.static.get and apoc.static.getAll have been migrated to functions, the procedures have been deprecated.
|
This section includes the following sub sections:
Working with API Credentials
The examples below assume that we have the following entries in the APOC configuration file (conf/apoc.conf
):
apoc.static.twitter.bearer=ABCDEF apoc.static.twitter.url=https://api.twitter.com/1.1/search/tweets.json?count=100&result_type=recent&lang=en&q=
apoc.static.twitter.bearer
value:RETURN apoc.static.get("twitter.bearer") AS value
value |
---|
"ABCDEF" |
twitter
prefixRETURN apoc.static.getAll("twitter") AS value
value |
---|
{"bearer":"ABCDEF","url":"https://api.twitter.com/1.1/search/tweets.json?count=100&result_type=recent&lang=en&q="} |
CALL apoc.static.set("twitter.user", "Michael")
value |
---|
null |
Caching Query Results
We can also use these procedures and functions to cache the results of queries.
CREATE (:Person {name: "Mark"})
CREATE (:Person {name: "Michael"})
CREATE (:Person {name: "Karin"})
CREATE (:Person {name: "Jennifer"})
m
and stores them as a static value:MATCH (p:Person)
WHERE not (p.name starts with "M")
WITH collect(p) AS people
CALL apoc.static.set("cached.people", people)
YIELD value
RETURN value
cached.people
static value:UNWIND apoc.static.get("cached.people") AS person
RETURN person, labels(person) AS label, apoc.meta.cypher.type(person) AS type
person | label | type |
---|---|---|
{"name":"Karin"} |
["Person"] |
"NODE" |
{"name":"Jennifer"} |
["Person"] |
"NODE" |