You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2016-11-11-using-firebase-as-a-json-cache.md
+17-5Lines changed: 17 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ title: Using Firebase as a JSON Cache
5
5
---
6
6
## Using A JSON Cache service
7
7
8
-
Good caching can reduce load on API's, save bandwidth costs, improve page load times and ultimately gives a better user experience. Any call can be cached on the server or in the browser, one way to reduce the load for a non dynamic server call for some JSON is to load the data into a JSON storage online as a intermediary stage. Your sever will essentially be shadowing this JSON cache and pushing to it when neccessary, therefore all the logic performed by your models needed to generate the JSON endpoint can be performed when needed and not every time a user requests the data.
8
+
Good caching can reduce load on API's, save bandwidth costs, improve page load times and ultimately gives a better user experience. Any call can be cached on the server or in the browser, one way to reduce the load for a non dynamic server call for some JSON is to load the data into a JSON storage online as a intermediary stage. Your sever will essentially be shadowing this JSON cache and pushing to it when necessary, therefore all the logic performed by your models needed to generate the JSON endpoint can be performed when needed and not every time a user requests the data.
9
9
10
10
I'll show an example using Firebase (https://firebase.google.com/), which is a service which allows you to read and write rapidly and concurrently to JSON storage online.
11
11
@@ -23,7 +23,7 @@ service firebase.storage {
23
23
24
24
Make sure to set the rules, for debugging it can be a good idea to simply open up read and write for everyone, make sure to restrict them for production.
25
25
26
-
The next stage is for you server API to push to the Firebase Storage. Here is an example of PHP Laravel Middleware using the observer pattern to push JSON to firebase storage, the API is first calling itself to get the response and then caching it. The logic will be similiar for different languages and frameworks.
26
+
The next stage is for you server API to push to the Firebase Storage. Here is an example of PHP Laravel Middleware using the observer pattern to push JSON to firebase storage, the API is first calling itself to get the response and then caching it. The logic will be similar for different languages and frameworks.
Finally the frontend application, whether you have a mobile app or a web application, needs to load the firebase plugin api and make a GET request to this https://herokuapp174.firebaseio.com/data.json. You may also need to authenticate correctly. The benefit of this system is that any encrytption or expensive database calls are no longer made by the server, it's essentially a backup data store which pushes whenever an admin updated a route with the middleware attached.
38
+
Finally the front-end application, whether you have a mobile app or a web application, needs to load the firebase plugin API and make a GET request to this https://herokuapp174.firebaseio.com/data.json. You may also need to authenticate correctly. The benefit of this system is that any encryption or expensive database calls are no longer made by the server, it's essentially a backup data store which pushes whenever an admin updated a route with the middleware attached.
39
39
40
-
Here is an example for an Angular app consuming the FireBase Json cache:
40
+
Here is an example for an Angular app consuming the Firebase JSON cache with CryptoJS decryption so that the data is at least obfuscated:
0 commit comments