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

apoc.static.get

- returns statically stored value from config (apoc.static.<key>) or server lifetime storage

Function

APOC Full

apoc.static.getAll

- returns statically stored values from config (apoc.static.<prefix>.*) or server lifetime storage

Function

APOC Full

apoc.static.set

- stores value under key for server lifetime storage, returns previously stored or configured value

Procedure

APOC Full

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=
The following returns the apoc.static.twitter.bearer value:
RETURN apoc.static.get("twitter.bearer") AS value
Table 1. Results
value

"ABCDEF"

The following returns all values with the twitter prefix
RETURN apoc.static.getAll("twitter") AS value
Table 2. Results
value

{"bearer":"ABCDEF","url":"https://api.twitter.com/1.1/search/tweets.json?count=100&result_type=recent&lang=en&q="}

The following stores an in memory value that lasts for the lifetime of the server:
CALL apoc.static.set("twitter.user", "Michael")
Table 3. Results
value

null

Caching Query Results

We can also use these procedures and functions to cache the results of queries.

The following creates a sample graph
CREATE (:Person {name: "Mark"})
CREATE (:Person {name: "Michael"})
CREATE (:Person {name: "Karin"})
CREATE (:Person {name: "Jennifer"})
The following finds people whose name does not start with the letter 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
The following retrieves those people from the 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
Table 4. Results
person label type

{"name":"Karin"}

["Person"]

"NODE"

{"name":"Jennifer"}

["Person"]

"NODE"