Backed by Redis, Mechanic offers a simple key/value cache store that you can use in your task scripts.

Cache values may be retrieved in task scripts using the cache object, e.g. {{ cache[key] }} .

For developers

This action requires an object with a single root key to define the cache operation, mapped to an object of arguments.

Operations

  • "set" 
  • "setex" 
  • "del" 

Operation arguments

  • "key" – required for all operations, must match /^[a-z0-9_:\-\.\/]+$/i 
  • "value" – required for "set", may be any JSON value, including arrays and objects
  • "ttl" – required for "setex", may be any integer from 0 to 5184000

Examples

Set a cache value (which will auto-expire in 60 days):

{
  "action": {
    "type": "cache",
    "options": {
      "set": {
        "key": "foobar",
        "value": 5
      }
    }
  }
}

Set a cache value to expire in 1 minute:

{
  "action": {
    "type": "cache",
    "options": {
      "setex": {
        "key": "foobar",
        "value": 5,
        "ttl": 60
      }
    }
  }
}

Clear a cache value:

{
  "action": {
    "type": "cache",
    "options": {
      "del": {
        "key": "foobar"
      }
    }
  }
}

Did this answer your question?