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

Commit

Permalink
feat: 設定 cache 時間為 1 小時
Browse files Browse the repository at this point in the history
  • Loading branch information
henry40408 committed May 16, 2018
1 parent 351b7ad commit 9515a42
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 28 deletions.
3 changes: 2 additions & 1 deletion app/scripts/background/chromeStorageService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import get from 'lodash/get'
import ChromePromise from 'chrome-promise/constructor'
import get from 'lodash/get'

import DIConstants from '../constants'

class ChromeStorageService {
Expand Down
19 changes: 13 additions & 6 deletions app/scripts/background/githubService.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import axios from 'axios/index'
import { cacheAdapterEnhancer } from 'axios-extensions'
import includes from 'lodash/includes'
import ApolloClient from 'apollo-boost'
import { cacheAdapterEnhancer } from 'axios-extensions'
import axios from 'axios/index'
import gql from 'graphql-tag'
import includes from 'lodash/includes'
import LRU from 'lru-cache'

import DIConstants from '../constants'

class GithubService {
AWESOME_LIST_URL = 'https://raw.githubusercontent.com/sindresorhus/awesome/master/readme.md'

LRU_MAX_AGE = 60 * 60 * 1000 // = 1 hour
RATE_LIMIT_THRESHOLD = 0.5

constructor (ctx) {
Expand All @@ -26,10 +27,12 @@ class GithubService {
/** @type {AxiosInstance} */
this.restfulClient = null

let defaultCache = LRU({ maxAge: this.LRU_MAX_AGE })

/** @type {AxiosInstance} */
this.rawRestfulClient = axios.create({
baseURL: `https://api.github.com`,
adapter: cacheAdapterEnhancer(axios.defaults.adapter)
adapter: cacheAdapterEnhancer(axios.defaults.adapter, { defaultCache })
})
}

Expand All @@ -49,16 +52,20 @@ class GithubService {
// suppress any GraphQL errors
let onError = ({ response }) => { response.errors = [] }

/** @type {ApolloClient} */
this.apolloClient = new ApolloClient({
uri: 'https://api.github.com/graphql',
request,
onError
})

let defaultCache = LRU({ maxAge: this.LRU_MAX_AGE })

/** @type {AxiosInstance} */
this.restfulClient = axios.create({
baseURL: 'https://api.github.com',
headers,
adapter: cacheAdapterEnhancer(axios.defaults.adapter)
adapter: cacheAdapterEnhancer(axios.defaults.adapter, { defaultCache })
})

this.accessToken.changed = false
Expand Down
3 changes: 2 additions & 1 deletion app/scripts/components/AccessTokenForm.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'

import { Box, Flex, reflex } from 'reflexbox'
import styled from 'styled-components'

import colors from '../themes/colors'

Expand Down
3 changes: 2 additions & 1 deletion app/scripts/components/RateLimit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react'
import PropTypes from 'prop-types'
import styled, { keyframes } from 'styled-components'

import { Flex, reflex } from 'reflexbox'
import styled, { keyframes } from 'styled-components'

import colors from '../themes/colors'

Expand Down
1 change: 1 addition & 0 deletions app/scripts/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import find from 'lodash/find'
import ParseGithubURL from 'parse-github-url'

import { log, logError } from './common'

import UpdateNotification from './components/UpdateNotification'
import StarHOC from './components/StarHOC'

Expand Down
2 changes: 2 additions & 0 deletions app/scripts/options.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom'

import { injectGlobal } from 'styled-components'

import colors from './themes/colors'

import OptionPage from './components/OptionPage'

// eslint-disable-next-line no-unused-expressions
Expand Down
3 changes: 2 additions & 1 deletion app/stories/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react'
import { storiesOf, addDecorator } from '@storybook/react'

import { action } from '@storybook/addon-actions'
import { withKnobs, boolean, number } from '@storybook/addon-knobs'
import { storiesOf, addDecorator } from '@storybook/react'

import styled from 'styled-components'

Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"gulp": "3.x.x",
"gulp-bump": "2.x.x",
"gulp-cache": "0.x.x",
"gulp-clean-css": "^3.x.x",
"gulp-clean-css": "~3.x.x",
"gulp-filter": "5.x.x",
"gulp-git": "2.x.x",
"gulp-if": "2.x.x",
Expand All @@ -61,9 +61,9 @@
"gulp-less": "3.x.x",
"gulp-livereload": "3.x.x",
"gulp-plumber": "1.x.x",
"gulp-sass": "^3.x.x",
"gulp-sass": "~3.x.x",
"gulp-sequence": "0.x.x",
"gulp-sourcemaps": "^2.x.x",
"gulp-sourcemaps": "~2.x.x",
"gulp-tag-version": "1.x.x",
"gulp-util": "3.x.x",
"gulp-zip": "4.x.x",
Expand All @@ -76,18 +76,18 @@
"yargs": "9.x.x"
},
"dependencies": {
"apollo-boost": "^0.1.6",
"apollo-boost": "~0.1.6",
"awilix": "~3.0.5",
"axios": "~0.18.0",
"axios-extensions": "^3.0.2",
"axios-extensions": "~3.0.2",
"bluebird": "~3.5.0",
"chomex": "~1.0.5",
"chrome-promise": "~3.0.0",
"date-fns": "~2.0.0-alpha.7",
"graphql": "^0.13.2",
"graphql-tag": "^2.9.2",
"graphql": "~0.13.2",
"graphql-tag": "~2.9.2",
"lodash": "~4.17.4",
"lru-cache": "~4.0.2",
"lru-cache": "~4.1.3",
"parse-github-url": "~1.0.0",
"prop-types": "~15.6.0",
"react": "~16.3.1",
Expand Down
27 changes: 17 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ anymatch@^1.3.0:
arrify "^1.0.0"
micromatch "^2.1.5"

apollo-boost@^0.1.6:
apollo-boost@~0.1.6:
version "0.1.6"
resolved "https://registry.yarnpkg.com/apollo-boost/-/apollo-boost-0.1.6.tgz#922d423536e408abfff816904ad2753d50feb9bf"
dependencies:
Expand Down Expand Up @@ -803,7 +803,7 @@ aws4@^1.2.1, aws4@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e"

axios-extensions@^3.0.2:
axios-extensions@~3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/axios-extensions/-/axios-extensions-3.0.2.tgz#bac9abd723ccdbfd638b7aa618d41c1a98384e38"
dependencies:
Expand Down Expand Up @@ -4910,11 +4910,11 @@ graphql-anywhere@^4.1.0-alpha.0, graphql-anywhere@^4.1.10:
dependencies:
apollo-utilities "^1.0.12"

graphql-tag@^2.4.2, graphql-tag@^2.9.2:
graphql-tag@^2.4.2, graphql-tag@~2.9.2:
version "2.9.2"
resolved "https://registry.yarnpkg.com/graphql-tag/-/graphql-tag-2.9.2.tgz#2f60a5a981375f430bf1e6e95992427dc18af686"

graphql@^0.13.2:
graphql@~0.13.2:
version "0.13.2"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-0.13.2.tgz#4c740ae3c222823e7004096f832e7b93b2108270"
dependencies:
Expand Down Expand Up @@ -4944,9 +4944,9 @@ gulp-cache@0.x.x:
try-json-parse "^0.1.1"
vinyl "^1.1.0"

gulp-clean-css@^3.x.x:
version "3.9.3"
resolved "https://registry.yarnpkg.com/gulp-clean-css/-/gulp-clean-css-3.9.3.tgz#47bf7ad62f44970f86e4ac4bdeed68ad904e65c5"
gulp-clean-css@~3.x.x:
version "3.9.4"
resolved "https://registry.yarnpkg.com/gulp-clean-css/-/gulp-clean-css-3.9.4.tgz#c6d3f8bb7a600fbe661962a72348a330954d343b"
dependencies:
clean-css "4.1.11"
plugin-error "1.0.1"
Expand Down Expand Up @@ -5063,7 +5063,7 @@ gulp-rename@^1.2.0:
version "1.2.2"
resolved "https://registry.yarnpkg.com/gulp-rename/-/gulp-rename-1.2.2.tgz#3ad4428763f05e2764dec1c67d868db275687817"

gulp-sass@^3.x.x:
gulp-sass@~3.x.x:
version "3.2.1"
resolved "https://registry.yarnpkg.com/gulp-sass/-/gulp-sass-3.2.1.tgz#2e3688a96fd8be1c0c01340750c191b2e79fab94"
dependencies:
Expand All @@ -5090,7 +5090,7 @@ gulp-sourcemaps@1.6.0:
through2 "^2.0.0"
vinyl "^1.0.0"

gulp-sourcemaps@^2.x.x:
gulp-sourcemaps@~2.x.x:
version "2.6.4"
resolved "https://registry.yarnpkg.com/gulp-sourcemaps/-/gulp-sourcemaps-2.6.4.tgz#cbb2008450b1bcce6cd23bf98337be751bf6e30a"
dependencies:
Expand Down Expand Up @@ -6627,7 +6627,7 @@ lru-cache@2:
version "2.7.3"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952"

lru-cache@^4.0.1, lru-cache@~4.0.2:
lru-cache@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.0.2.tgz#1d17679c069cda5d040991a09dbc2c0db377e55e"
dependencies:
Expand All @@ -6641,6 +6641,13 @@ lru-cache@^4.1.1:
pseudomap "^1.0.2"
yallist "^2.1.2"

lru-cache@~4.1.3:
version "4.1.3"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.3.tgz#a1175cf3496dfc8436c156c334b4955992bce69c"
dependencies:
pseudomap "^1.0.2"
yallist "^2.1.2"

lru-queue@0.1:
version "0.1.0"
resolved "https://registry.yarnpkg.com/lru-queue/-/lru-queue-0.1.0.tgz#2738bd9f0d3cf4f84490c5736c48699ac632cda3"
Expand Down

0 comments on commit 9515a42

Please sign in to comment.