Skip to content
This repository was archived by the owner on Jul 14, 2022. It is now read-only.

Quick Start: Add Caching

WWitman edited this page Sep 5, 2014 · 9 revisions

Adding caching to your API

Adding caching is very similar to adding a quota.

  • First, update your package.json file in your project to include the volos-cache-memory": module under
        "dependencies": {
             "express": "",
             "a127-magic": "",
             "volos-cache-memory": ""
        }

Note: You can also use a cache implementation that uses Redis or Apigee as its provider. More information here.

  • Run, npm install.

  • Execute a127 project edit to open up the Swagger editor.

  • In the Swagger configuration file, under x-volos-resources, add the following to enable an in-memory cache provider named 'cache' that you refer to later:

        cache:     
            provider: volos-cache-memory
            options:
                name: weather-cache
                ttl: 60000
  • Finally, use x-volos-apply to apply this policy to the paths you want to enforce quotas on, referencing the resource you defined in the previous step:
        paths:     
            /weather:
                x-swagger-router-controller: weather
                x-volos-authorizations: {}
                x-volos-apply:
                    quota: {}
                    cache: {}

Now, try running the app as in the quickstart and try using the curl command:

    a127 project start
    curl http://localhost:10010/weather\?city\=San%20Jose,CA
Clone this wiki locally