View Book.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
const mongoose = require("mongoose"); | |
const { Schema } = mongoose; | |
const bookSchema = new Schema({ | |
title: String, | |
content: String, | |
createdAt: { type: Date, default: Date.now }, | |
author: String | |
}); |
View bookRoutesBeforeCache.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
const mongoose = require("mongoose"); | |
const Book = mongoose.model("Book"); | |
module.exports = app => { | |
app.get("/api/books", async (req, res) => { | |
let books; | |
if (req.query.author) { | |
books = await Book.find({ author: req.query.author }) | |
} else { | |
books = await Book.find() |
View cache.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
const mongoose = require("mongoose"); | |
const redis = require("redis"); | |
const keys = require("../config/keys"); | |
const client = redis.createClient({ | |
host: keys.redisHost, | |
port: keys.redisPort, | |
retry_strategy: () => 1000 | |
}); |
View cache.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
const mongoose = require("mongoose"); | |
const redis = require("redis"); | |
const util = require("util"); | |
const keys = require("../config/keys"); | |
const client = redis.createClient({ | |
host: keys.redisHost, | |
port: keys.redisPort, | |
retry_strategy: () => 1000 | |
}); |
View index.tsx
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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { createStore, applyMiddleware } from 'redux'; | |
import { Provider } from 'react-redux'; | |
import thunk from 'redux-thunk'; | |
import { App } from './components/App'; | |
import { reducers } from './reducers'; | |
const store = createStore(reducers, applyMiddleware(thunk)); |
View App.tsx
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
import React from 'react'; | |
export class App extends React.Component { | |
render() { | |
return <div>Hello World</div>; | |
} | |
} |
View index.ts
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
import { combineReducers } from 'redux'; | |
export const reducers = combineReducers({ | |
dummy: () => 'dummy reducer', | |
}); |
View bookRoutes.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
const mongoose = require("mongoose"); | |
const { clearKey } = require("../services/cache"); | |
const Book = mongoose.model("Book"); | |
module.exports = app => { | |
app.get("/api/books", async (req, res) => { | |
let books; | |
if (req.query.author) { | |
books = await Book.find({ author: req.query.author }).cache(); | |
} else { |
View cache.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
const mongoose = require("mongoose"); | |
const redis = require("redis"); | |
const util = require("util"); | |
const keys = require("../config/keys"); | |
const client = redis.createClient({ | |
host: keys.redisHost, | |
port: keys.redisPort, | |
retry_strategy: () => 1000 | |
}); |