-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3418 from Vizzuality/feature/request-cache
Feature/request cache
- Loading branch information
Showing
32 changed files
with
346 additions
and
93 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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.