Managing data sources

Caching

We're working on it...

This guide is under construction. If you hit some rough edges, or find it confusing, come yell at us on slack.

Caching requests

By default, Orbital will cache requests throughout a query only. ie., Orbital will only call a service with the same set of parameters once within a query.

However, caches are destroyed at the end of each query.

To enable caching, simply add @Cache to the top of your query:

@Cache
find { Film[] } as {
  id : FilmId
  // Fetched from a remote service.
  // Calls will be cached.
  currentReviewScore : ReviewScore
}

Scoping caches

By default, all queries share the same cache. If you want cache isolation, so that population and invalidation are isolated from each other, you can apply a name to the cache:

@Cache("myCache")
find { Film[] } as {
  id : FilmId
  // Fetched from a remote service.
  // Calls will be cached.
  currentReviewScore : ReviewScore
}

Using Orbital's local cache

Orbital’s local cache runs in-process within Orbital.

It’s the default cache that’s enabled if no connection is provided.

It’s helpful for development, but shouldn’t be taken to production, as excessive caching can cause Out-of-Memory failures and degrade performance.

// This query uses the default, local cache
@Cache
find { Film[] } as {
  id : FilmId
  // Fetched from a remote service
  currentReviewScore : ReviewScore
}

Cache TTL

Orbital’s internal cache contains a TTL of 5 minutes.

This can’t currently be configured, as the cache is not intended for production use.

Using an external cache

Orbital supports external caches, and will run a near-cache in-process, offloading to the remote cache as the library supports.

To enable a remote cache, first define a connection to the cache in your connections.conf file, then specify the name of the connection in your query.

connections.conf
hazelcast {
   myHazelcast {
      connectionName = myHazelcast
      addresses = ["localhost:5701"]
   }
}
query.taxi
@Cache(connection = "myHazelcast")
find { Film[] } as {
  id : FilmId
  // Fetched from a remote service
  currentReviewScore : ReviewScore
}

Supported caches

Orbital supports caching with the following platforms:

  • Hazelcast
  • Redis

If you need cache not listed, please reach out on slack

Cache TTL

The default Cache TTL is defined in the connections file:

connections.conf
hazelcast {
   myHazelcast {
      connectionName = myHazelcast
      addresses = ["localhost:5701"]
      ttl = 20 minutes
   }
}

max-age headers

Orbital will honour max-age headers when caching responses from HTTP services:

Setting the cache-control: max-age= header will cause the entry to be automatically evicted after the max-age expires.

Previous
AWS services
Next
Writing queries