https://github.com/fdesjardins/proxycache
Web proxy caching for Node [Not Maintained]
https://github.com/fdesjardins/proxycache
cache file-cache google-cloud google-cloud-storage nodejs proxy proxy-cache proxycache
Last synced: 6 months ago
JSON representation
Web proxy caching for Node [Not Maintained]
- Host: GitHub
- URL: https://github.com/fdesjardins/proxycache
- Owner: fdesjardins
- License: mit
- Created: 2016-08-29T07:02:54.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-01-06T06:25:41.000Z (about 8 years ago)
- Last Synced: 2025-03-09T01:04:54.086Z (12 months ago)
- Topics: cache, file-cache, google-cloud, google-cloud-storage, nodejs, proxy, proxy-cache, proxycache
- Language: JavaScript
- Homepage:
- Size: 151 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# proxycache
[](https://travis-ci.org/fdesjardins/proxycache)
[](https://www.npmjs.org/package/proxycache)
[](https://coveralls.io/github/fdesjardins/proxycache?branch=master)
A simple, configurable, Redis-powered caching proxy.
Use it when you want to
- deliver a URL to a static file
- cache the file somewhere
- provide a URL to the cached version for subsequent requests
# Install
```
$ npm install --save proxycache
```
# Example
```javascript
const express = require('express')
const request = require('request')
const proxycache = require('proxycache')
// Create Redis/Cloud Storage proxycache client
const config = {
store: {
client: 'redis',
connection: {}
},
cache: {
client: 'gcloud',
connection: {
keyFilename: './gcloud-key.json',
projectId: 'my-project-id'
},
options: {
bucket: 'images'
}
}
}
let cache
proxycache(config).then(client => {
cache = client
})
// Image server to proxy for
const imgsrv = express()
imgsrv.get('/images/:id', (req, res) => {
const id = req.params.id
request.get(`http://www.fillmurray.com/g/${id}/${id}`).pipe(res)
})
imgsrv.listen(3888)
console.log('Image server listening on 3888')
const render = src => `
bfm
`
// API Server
const app = express()
app.get('/images/:id', (req, res) => {
const id = req.params.id
// query the cache
cache.get(id).then(result => {
// cache hit
if (result) {
return res.end(render(result))
}
const uri = `http://localhost:3888/images/${id}`
// cache miss; send the default url
res.end(render(uri))
// cache the file; TTL in seconds
cache.set(id, uri, 60)
})
})
app.listen(8000)
```
## API
### proxycache(options)
#### options
#####
Type: `object`
# License
MIT © [Forrest Desjardins](https://github.com/fdesjardins)