## 20.3. Static Value Storage

This section describes procedures and functions for storing and retrieving static values.

The library has support for storing and retrieving static values, functionality that can be used to work with API credentials or cache query results.

`apoc.static.get(name)` | returns statically stored value from config (apoc.static.<key>) or server lifetime storage
`apoc.static.getAll(prefix)` | returns statically stored values from config (apoc.static.<prefix>) or server lifetime storage
`apoc.static.set(name, value)` | stores value under key for server livetime 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:

- Section 20.3.1, “Working with API Credentials”
- Section 20.3.2, “Caching Query Results”

### 20.3.1. Working with API Credentials

The examples below assume that we have the following entries in the Neo4j configuration file:

    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 20.4. Results
value
"ABCDEF"

The following returns all values with the `twitter` prefix.

    RETURN apoc.static.getAll("twitter") AS value

Table 20.5. 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 20.6. Results
value
null

### 20.3.2. 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 20.7. Results
person | label | type
--- | --- | ---
{"name":"Karin"} | ["Person"] | "NODE"
{"name":"Jennifer"} | ["Person"] | "NODE"