-
Notifications
You must be signed in to change notification settings - Fork 96
Feature/request cache #3418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feature/request cache #3418
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
92d1d07
first approach installing redis
pjosh 4ce132d
adding a method to get all redis keys
pjosh 443a20e
cache provider & cache service
pjosh 60b9033
endpoint fixes
pjosh e6e76ba
cache service methods
pjosh 55e444c
request wrapper
pjosh 94fe988
Merge branch 'develop' of https://github.com/Vizzuality/gfw into feat…
pjosh 0d75e65
cache middleware to get the cache keys from Redux
pjosh 0994ff9
using the new request function in all services
pjosh 96075f9
fix json structure
pjosh 81d0595
fix the asynchronous issue with the other providers
pjosh 892aae6
fix an asynchronous issue with the parent pattern
pjosh c5bbe21
check if cache is down
pjosh 0dd8edc
adding expire
pjosh 83a926e
fix expire method
pjosh 51cb281
adding cache exceptions
pjosh 93498e4
improve request interceptor
pjosh b7ee226
remove db expire
pjosh a445589
test to flush redis in the Procfiles
pjosh 66ffd42
change script order
pjosh ebddf64
revert Procfile changes
pjosh 5c29e0b
Merge branch 'develop' of https://github.com/Vizzuality/gfw into feat…
pjosh 32d9b6b
prevent errors
pjosh 3fb3da8
run redis on server start
pjosh 79ec245
readme notes
pjosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
web: bundle exec rails s | ||
web: redis-server /usr/local/etc/redis.conf | ||
# watcher: ./bin/webpack-watcher | ||
webpacker: ./bin/webpack-dev-server |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class CacheController < ApplicationController | ||
skip_before_action :verify_authenticity_token | ||
|
||
def index | ||
data = $redis.get(params[:id]) | ||
if data | ||
data = JSON.parse(data) | ||
end | ||
|
||
render :json => data | ||
end | ||
|
||
def add | ||
id = params[:id] | ||
data = params[:data].to_json | ||
expire = params[:expire] || 86400 | ||
$redis.set(id, data, ex: expire) | ||
|
||
render :json => { id: id, data: data, expire: expire } | ||
end | ||
|
||
def keys | ||
data = $redis.keys('*') | ||
render :json => { data: data } | ||
end | ||
|
||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
{ | ||
"id": "gladRequest", | ||
"type": "excludeWeekDay", | ||
"data": [4, 5] | ||
} | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
app/javascript/providers/cache-provider/cache-provider-actions.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createAction } from 'redux-actions'; | ||
import { createThunkAction } from 'utils/redux'; | ||
|
||
import { getKeys } from 'services/cache'; | ||
|
||
export const setCacheList = createAction('setCacheList'); | ||
export const setCacheError = createAction('setCacheError'); | ||
|
||
export const getCacheList = createThunkAction( | ||
'getCacheList', | ||
() => dispatch => { | ||
getKeys() | ||
.then(response => { | ||
if (response.data.data) { | ||
dispatch(setCacheList(response.data.data)); | ||
} else { | ||
dispatch(setCacheError(true)); | ||
} | ||
}) | ||
.catch(error => { | ||
dispatch(setCacheError(true)); | ||
console.info(error); | ||
}); | ||
} | ||
); |
22 changes: 22 additions & 0 deletions
22
app/javascript/providers/cache-provider/cache-provider-reducers.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export const initialState = { | ||
cacheListLoading: true, | ||
cacheList: [], | ||
error: false | ||
}; | ||
|
||
const setCacheList = (state, { payload }) => ({ | ||
...state, | ||
cacheListLoading: false, | ||
cacheList: payload | ||
}); | ||
|
||
const setCacheError = (state, { payload }) => ({ | ||
...state, | ||
cacheListLoading: false, | ||
error: payload | ||
}); | ||
|
||
export default { | ||
setCacheList, | ||
setCacheError | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { PureComponent } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import * as actions from './cache-provider-actions'; | ||
import reducers, { initialState } from './cache-provider-reducers'; | ||
|
||
class CacheProvider extends PureComponent { | ||
componentWillMount() { | ||
const { getCacheList } = this.props; | ||
getCacheList(); | ||
} | ||
|
||
render() { | ||
return null; | ||
} | ||
} | ||
|
||
CacheProvider.propTypes = { | ||
getCacheList: PropTypes.func.isRequired | ||
}; | ||
|
||
export { actions, reducers, initialState }; | ||
export default connect(null, actions)(CacheProvider); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we automate this to happen on build? So when we deploy the cache is flushed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will not be possible 😭 😭 I've spent almost the whole day yesterday, trying to find a solution, but Heroku is a very hard bastard. I wanted to talk to someone expert in Heroku to see if he could come up with any solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well that is very annoying. maybe @simaob can help?