Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.

Commit ee1c8fd

Browse files
committed
Add caching to API requests
Release v1.2
1 parent bcf117a commit ee1c8fd

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> A Chrome extension that filters through Facebook Dev Circles around the world to get only the interesting posts in your feed.
44
5-
## [Download the extension (.crx)](https://github.com/sidvishnoi/fb-dev-interest/releases/download/v1.1/Merge.Facebook.Dev.Circles.by.Interests.crx)
5+
## [Download the extension (.crx)](https://github.com/sidvishnoi/fb-dev-interest/releases/download/v1.2/Merge.Facebook.Dev.Circles.by.Interests.crx)
66

77
# How to Install
88

dist/inject.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 2,
33
"name": "Merge Facebook Dev Circles by Interests",
44
"description": "A Chrome extension that filters through Facebook Dev Circles around the world to get only the interesting posts in your feed.",
5-
"version": "1.0",
5+
"version": "1.2",
66
"icons":
77
{
88
"16": "icon16.png",

inject.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,22 @@ fbDevInterest.getComments = function(postid, parent) {
222222
const commentsArea = createCommentArea(postid, parent);
223223

224224
const fetchUrl = self.COMMENTS_API_URL.replace('POSTID', postid);
225+
226+
let cachedResult = localStorage.getItem(fetchUrl);
227+
if (cachedResult) {
228+
cachedResult = JSON.parse(cachedResult);
229+
const minuteDiff = (new Date() - new Date(cachedResult.last_fetch_time)) / (1000*60);
230+
if (minuteDiff < 10) { // 10 min cache
231+
return handleJsonResponse(cachedResult);
232+
}
233+
}
234+
225235
self.requestList.add(fetchUrl);
226236
fetch(fetchUrl)
227237
.then(res => res.json())
228238
.then((json) => {
239+
json.last_fetch_time = new Date();
240+
localStorage.setItem(fetchUrl, JSON.stringify(json));
229241
self.requestList.delete(fetchUrl);
230242
self.showComments(json, commentsArea);
231243
})
@@ -451,10 +463,22 @@ fbDevInterest.getGroupFeed = function(options) {
451463
});
452464
self.showPost(errorPost);
453465
}
466+
467+
let cachedResult = localStorage.getItem(fetchUrl);
468+
if (cachedResult) {
469+
cachedResult = JSON.parse(cachedResult);
470+
const minuteDiff = (new Date() - new Date(cachedResult.last_fetch_time)) / (1000*60);
471+
if (minuteDiff < 10) { // 10 min cache
472+
return handleJsonResponse(cachedResult);
473+
}
474+
}
475+
454476
self.requestList.add(fetchUrl);
455477
fetch(fetchUrl)
456478
.then((res) => res.json())
457479
.then((json) => {
480+
json.last_fetch_time = new Date();
481+
localStorage.setItem(fetchUrl, JSON.stringify(json));
458482
self.requestList.delete(fetchUrl);
459483
handleJsonResponse(json);
460484
})

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 2,
33
"name": "Merge Facebook Dev Circles by Interests",
44
"description": "A Chrome extension that filters through Facebook Dev Circles around the world to get only the interesting posts in your feed.",
5-
"version": "1.0",
5+
"version": "1.2",
66
"icons":
77
{
88
"16": "icon16.png",

0 commit comments

Comments
 (0)