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

fernyettheplant/axios-elasticache-memcached-adapter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

axios-elasticache-memcached-adapter

Cache adapter for axios using memcached elasticache

This library was built on top of memcached-elasticache to support http requests caching using AWS ElastiCache

David npm node npm js-standard-style

Disclaimer

This library was built only for server side usage.

Install

npm install --save axios-elasticache-memcached-adapter

Setting up the client

The library setup takes four parameters

  • serverLocations: Server Location of memcached cluster. Check Server Locations documentation from the memcached library.
  • ttl: Cache Time-to-Live in seconds. Default value is 100 seconds.
  • salt: Salt Suffix for the memcached key. Default is empty string ''
  • options: Options object with the memcached client params. Check the client options documentation from the memcached library.

Usage

To use this library, you need to setup the memcached options to create the adapter function and then attach it to the axios instance.

const axios = require('axios')
const axiosCacheMemcached = require('axios-elasticache-memcached-adapter')

const memcachedAdapter = axiosCacheMemcached.setup('localhost:11211')

const http = axios.create({
  adapter: memcahachedAdapter
})

http.get(url, options).then(response => {
  // Cached or Uncached axios response
})

or

const axios = require('axios')
const axiosCacheMemcached = require('axios-elasticache-memcached-adapter')

const memcachedAdapter = axiosCacheMemcached.setup('mycfgmemcached.endpoint.elasticache.aws.amazon.com', 600, 'mysalt2.com', { maxValue: 1024 * 1024 * 5 })

axios.get(url, {
  params: theparams,
  adapter: memcachedAdapter
})

License

This project is released under the MIT license. See the LICENSE for more information.