<p>Not sure how you can do this, but you could manually print the response to a file yourself on a regular basis (as a cron job) using wget:</p>

<p>This:</p>

<pre><code>wget -S http://craft.fira/fullmembers.json
</code></pre>

<p>…saves the JSON into a file named fullmembers.json into the directory it was run from.</p>

<p>Here is the solution that I have used in a cron job that runs every minute:</p>

<pre><code>wget -O - http://www.fira.co.uk/fullmembers.json &gt; /home/forge/www.fira.co.uk/public/jsoncache/fullmembers-temp.json
rm /home/forge/www.fira.co.uk/public/jsoncache/fullmembers.json
mv /home/forge/www.fira.co.uk/public/jsoncache/fullmembers-temp.json /home/forge/www.fira.co.uk/public/jsoncache/fullmembers.json
</code></pre>

CC BY-SA 3.0
2016-08-22T14:36:29.323Z
Interesting. Have you noticed a big improvement in the speed of data access from the app(s) consuming the API? At the moment this is a bottleneck for me. I'm not sure if it's the server response time or the DB queries
Ian Young
CC BY-SA 3.0
2016-08-23T08:47:59.703Z
For what I have been using it for the response time has been very quick. I have made sure to keep the limit fairly low and rinse pagination, otherwise that does slow it down, plus I have been using eager loading where I can.
zizther
CC BY-SA 3.0
2016-01-29T11:29:55.707Z
2016-06-09T11:22:00.720Z
2016-06-09T11:22:00.720Z
Adam Menczykowski
<p>Is it possible to create static JSON file using the Element API plugin?</p>

<p>What I then want to do was cache that file probably using Varnish or push it to an S3 bucket.</p>

<p>If I was to cache it I would need to look at purging the URL when an entry is added or edited.
If I pushed it to S3, then I would either need to overwrite the file or manage it another way.</p>

<p>What would be the best way to handle this, and could you easily create a static JSON file with caching and purging abilities?</p>

CC BY-SA 3.0
2016-02-26T14:20:05.643Z
Would it be an option to cache it locally? The Craft HTMLCache plugin (https://github.com/craftapi/htmlcache) is currently in beta, but busts the cache when an entry is edited and automatically expires after an hour..
chris
CC BY-SA 3.0
2016-08-23T08:39:58.433Z
Was HTMLCache useful in this case or did you go with another method? I'm in a similar situation now so just curious as to what worked for other people.
Ian Young
<cache><plugin-elementapi><varnish>
How to create a static JSON files with Element API and cache it with Varnish
# How to create a static JSON files with Element API and cache it with Varnish

(Asked by: username_0 on 2015-11-13)

Is it possible to create static JSON file using the Element API plugin?

What I then want to do was cache that file probably using Varnish or push it to an S3 bucket.

If I was to cache it I would need to look at purging the URL when an entry is added or edited.
If I pushed it to S3, then I would either need to overwrite the file or manage it another way.

What would be the best way to handle this, and could you easily create a static JSON file with caching and purging abilities?

**Tags:** cache, plugin-elementapi, varnish
> **Comments:**
> **username_1**: Would it be an option to cache it locally? The Craft HTMLCache plugin (https://github.com/craftapi/htmlcache) is currently in beta, but busts the cache when an entry is edited and automatically expires after an hour..  
> **username_2**: Was HTMLCache useful in this case or did you go with another method? I'm in a similar situation now so just curious as to what worked for other people.  

---

## 1 answers

### Answer by username_3 on 2016-01-29. Score: 3

Not sure how you can do this, but you could manually print the response to a file yourself on a regular basis (as a cron job) using wget:
This:
wget -S http://craft.fira/fullmembers.json

…saves the JSON into a file named fullmembers.json into the directory it was run from.
Here is the solution that I have used in a cron job that runs every minute:
wget -O - http://www.fira.co.uk/fullmembers.json > /home/forge/www.fira.co.uk/public/jsoncache/fullmembers-temp.json
rm /home/forge/www.fira.co.uk/public/jsoncache/fullmembers.json
mv /home/forge/www.fira.co.uk/public/jsoncache/fullmembers-temp.json /home/forge/www.fira.co.uk/public/jsoncache/fullmembers.json

> **Comments:**
> **username_2**: Interesting. Have you noticed a big improvement in the speed of data access from the app(s) consuming the API? At the moment this is a bottleneck for me. I'm not sure if it's the server response time or the DB queries  
> **username_0**: For what I have been using it for the response time has been very quick. I have made sure to keep the limit fairly low and rinse pagination, otherwise that does slow it down, plus I have been using eager loading where I can.  

---

