Skip to content
Roy Lechich edited this page Jul 25, 2017 · 7 revisions

Redis Caching

The AnnotationServer allows for caching the results of searching for all annotations on a given canvas, using Redis, which is an in-memory database

This is currently a simple feature implemented as follow:
1 add REDIS to the server. We currently implement our servers on Heroku, so it is a simple matter of provisioning the app with the Heroku Redis add-on.
2 Once you have the url for the Redis service, add these as environment configuration variables:

  •  USE_REDIS: (Y/N)
    
  •  REDIS_URL:
    

The main retrieval method used in the annotations controller is #getAnnotationsForCanvasViaList

If USE_REDIS is set to "Y" it will attempt to find the key with the name matching the canvas in the Redis database, and use its value instead of re-fetching, composing and serializing the JSON response. This results in much faster response time.


To set the Redis key for a canvas, access the server via route: http://{server host url}/setRedisKeys?canvas_id={canvas_id}

This request is routed to annotations#setRedisKeys, which will store the results of the call to #getAnnotationsForCanvasViaList into a Redis record with the canvas_id as part of the key name.

Currently the USE_REDIS configuration variable must be set to "N" before calling this method, then reset to "Y" after it is completed.

The Redis caching is useful when there are canvases with a lot of annotations. It was implemented because for one of the projects, each (large) canvas had so many annotations that the response could take up to 30 seconds without using Redis.

Redis has a command line interaction via redis-cli; in heroku it is heroku redis:cli. This provides a simple environment to list all keys, examine one key value, etc:

keys *
get thisKey
and so on.

Clone this wiki locally