Caching and Optimization
Optimization
The goal of PyroStreams is to be as transparent a layer as possible between a database schema and an abstraction to pull data from it. Obviously, it's good to optimize database interactions as much as possible for performance, and PyroStreams gives you a few tools to allow you to keep your database queries low.
Disabling Fields
You can disable any fields you'd like in stream functions using the disable parameter. This essentially tells PyroStreams to bypass the row formatting, which allows you to minimize resource use.
You can separate multiple fields with a pipe character:
disable="field_one|field_two|field_three"
A popular field to ignore is the created_by - this is the field that is automatically created with each stream and gathers user data about who created the entry.
Tag Caching
PyroStreams offer two different types of tag caching - full tag caching and query caching. Caching is available on the following functions:
- cycle
- single
- multiple
- calendar
Full Tag Caching
This type of caching caches the entire output of the tag. This is useful when you have some static content being generated by PyroStreams that you want to cache.
Query Caching
Query caching caches the actual queries that are run within PyroStreams, and not the actual tag output. For instance, if you have a list of messages that you are displaying with PyroStreams and you run the date/time of the message through a function that displays how long ago the message was sent basedon the current time, query caching is the solution for you, since it will cache the gathering of data but not plugin that takes that data and parses it.
Using Caching
There are three parameters available to the functions that support caching within PyroStreams.
| Parameter | Default | Description |
|---|---|---|
| cache | This is the number of minutes (or seconds) you would like to keep the cache for. Setting this to a number turns on caching for that tag. | |
| cache_time_format | minutes | When you set the cache time number with the cache parameter, you are setting it in minutes by default. However, you can choose to set the cache time in seconds if you'd like by setting this parameter to "seconds". |
| cache_type | query | As explained above, you can either cache the full tag or the query. Set this to "tag" to cache the tag. |
A simple usage example would be:
{{ streams:cycle stream="listings" limit="20" cache="20" }}
The above would cache the queries within the tag for 20 minutes.
{{ streams:cycle stream="listings" limit="20" cache="45" cache_time_format="seconds" }}
The above would cache the queries within the tag for 45 seconds.
{{ streams:cycle stream="listings" limit="20" cache="10" cache_type="tag" }}
The above would cache the entire tag output for 10 minutes.
