This topic discusses all the aspects of the cache engine in Twig Anything.
What is cache
For every Twig Template, there is a setting:
If you leave it empty, the data source will be fetched every time it is used in your site.
For instance, if your template reads data from some API, a new HTTP call will be made each time the template is shown in a wordpress page or post.
If 10 users open your site, 10 HTTP calls will be made. This is not good and you would likely want to retrieve data once only and then cache it in WordPress locally and reuse it.
That is where Cache lifetime in seconds comes into play.
If you set it to 60 seconds (= 1 minute), data will be re-fetched not more often than once a minute. If 10 users open your site within a minute, the local cached version will be used.
When to use cache and when not to
Caching helps to considerably reduce data fetching. But is it always needed? Actually, no.
Set cache lifetime when reading data from:
- medium and large local files
- MySQL database with heavy queries
If you don't cache data that comes from a URL, your website might freeze as soon as it is opened by many users simultaneously. It will also let your server eat more traffic.
Do not set cache lifetime when reading data from:
- small files, for example a CSV file with 100 lines
- WordPress MySQL database with queries (except very heavy queries that run for a second or longer)
Where cache is saved
Twig Anything uses standard WordPress transient mechanism to store cache.
By default, it is saved in database. However, Transients are inherently sped up by caching plugins. For example, a memcached plugin would make WordPress store transient values in fast memory instead of in the database.
This means that if you use caching plugins with your site, Twig Anything will benefit from it as well.