Intro to Persisted Datasets

Extensibility and performance are often in conflict. Some large datasets can be resource intensive to process, so users might be left waiting seconds, or even minutes for results. Other datasets, like getting an attribute of another attribute, might perform adequately, but cause issues at scale. With Persisted Datasets you can shape data for speed and reuse demanding queries without worrying about performance.

By simply caching data as JSON, you can re-use it for later transformations (website, app, etc.) without having to rebuild it from scratch. Persisted Datasets are cached on the database or in memory and can be called by Lava filters to transform data for as many uses as you can think of.

How Persisted Datasets Work

Let’s take a look at what makes Persisted Datasets tick.

Output

To output a persisted dataset, you just need to use the PersistedDataset Lava filter, which looks something like this:

{%- assign data = 'mydataset' | PersistedDataset -%}
{%- for item in data -%}
  {{ item.Title }}
{%- endfor -%}
                

In the above example, mydataset is the name of the Persisted Dataset Access Key and data returns the data contained in the dataset. You can find more information on how to use the PersistedDataset Lava filter in the How to Use It section below.

Behind the Scenes

To create a Persisted Dataset, you’ll use a Lava-based build script to create JSON, which is then stored in memory.

[
    {% campus where:'Id != "0"' %}
        {% for item in campusItems %}
            {
                "Id": {{ item.Id | ToJSON }},
                "Name": {{ item.Name | ToJSON }}
            }
            {% if forloop.last == false %},{% endif %}
        {% endfor %}
    {% endcampus %}
]
                

Because this is Lava-enabled, you have access to all the power of Lava, including SQL, Entity Commands, Execute and Web Requests.