Cache


Overview


Actionhero includes a powerful cache system based on Redis. It can be used to store and retrieve data, but also to create more complex data structures based on queues and expiring object.


Methods


The cache methods are documented in detail with annotations here. There are methods fall into 3 categories:

  • data: read, write, check, delete
  • locks you can lock and unlock objects in the cache so that only one Actionhero node can claim it
  • queues you can share a distributed array and access it via push and pop methods

Example Usage


An Action:

import { cache, Action } from "actionhero";

export class CacheTest extends Action {
  constructor() {
    super();
    this.name = "cacheTest";
    this.description = "I will test the internal cache functions of the API";
    this.inputs = {
      key: {
        required: true,
        formatter: this.stringFormatter,
        validator: this.stringValidator
      },

      value: {
        required: true,
        formatter: this.stringFormatter,
        validator: this.stringValidator
      }
    };
    this.outputExample = {
      cacheTestResults: {
        saveResp: true,
        sizeResp: 1,
        loadResp: {
          key: "cacheTest_key",
          value: "value",
          expireTimestamp: 1420953274716,
          createdAt: 1420953269716,
          readAt: null
        },
        deleteResp: true
      }
    };
  }

  stringFormatter(s) {
    return String(s);
  }

  stringValidator(s) {
    if (s.length < 3) {
      return "inputs should be at least 3 letters long";
    } else {
      return true;
    }
  }

  async run({ params, response }) {
    const key = `cacheTest_${params.key}`;
    const value = params.value;

    response.cacheTestResults = {
      saveResp: await cache.save(key, value, 5000),
      sizeResp: await cache.size(),
      loadResp: await cache.load(key),
      deleteResp: await cache.destroy(key)
    };
  }
}

    Solutions

    Actionhero was built from the ground up to include all the features you expect from a modern API framework.

    Open Source


    The Actionhero server is open source, under the Apache-2 license


    Actionhero runs on Linux, OS X, and Windows


    You always have access to the Actionhero team via Slack and Github



    Premium Training & Review


    We provide support for corporate & nonprofit customers starting at a flat rate of $150/hr. Our services include:


    • Remote training for your team
    • Code Reviews
    • Best Practices Audits
    • Custom plugin & Feature Development

    We have packages appropriate for all company sizes. Contact us to learn more.


    Premium Training & Review


    We provide support for corporate & nonprofit customers starting at a flat rate of $150/hr. Our services include:


    • Remote training for your team
    • Code Reviews
    • Best Practices Workshops
    • Custom plugin & Feature Development

    We have packages appropriate for all company sizes. Contact us to learn more.


    Enterprise


    For larger customers in need of a support contract, we offer an enterprise plan including everything in the Premium plan plus:


    • 24/7 access to core members of the Actionhero Team
    • Emergency response packages
    • Deployment support
    • ...and custom development against Actionhero’s core as needed.