Skip to content
Gavin Zhang edited this page Jul 9, 2019 · 13 revisions

Welcome to the service-cache wiki! In this wiki, you will learn how service-cache help you enhance the service performance and reduce latency by using cache.

Annotate a service

When you want to enable cache for a service, what you have to do is simply adding annotations for the service.

You are free to choose what resources of a service are cacheable.

Cache for the whole service

metadata:
  annotations:
    service-cache.github.io/default: "true"

Cache for only some of URIs of the service

metadata:
  annotations:
    service-cache.github.io/default: 'true'
    service-cache.github.io/URLs: '["/foo", "/bar"]'

or disabled caching by default, but allow caching for only some of resources:

metadata:
  annotations:
    service-cache.github.io/default: 'false'
    service-cache.github.io/URLs: '["/foo", "/bar"]'

Create a ServiceCache object

An alternative way to add cache for a services is, create a custom resource - ServiceCache. By creating a ServiceCache resource, you tell Service Cache what service and its resources are going to be cached.

Under the hood

To process the above two ways of caching for services, you need to deploy a kubernetes operator. The kubernetes operator monitors services and ServiceCache and correlates them.

The kubernetes operator has two controllers, each of them is used to do following.

service's annotation

The first Kubernetes controller is used to monitor what services are to be service-cache enabled. When a service is annotated, the kubernetes controller creates a custom resource - ServiceCache for it.

When the annotations in a service are updated or deleted, its corresponding ServiceCache object is also updated or deleted.

Custom Resource - ServiceCache

The second Kubernetes controller is used to monitor ServiceCache. Once it knows a ServiceCache has been created or updated, it checks and ensures the service related to this ServiceCache is also annotated and synced.

When a ServiceCache object is deleted, the operator also removes the annotations from the related service.

Service-cache Envoy Filter

The Envoy filter is a filter of Istio Envoy proxy. It is used to intercept the requests and determine if the cacheable response should be returned, based on the configurations stored in ServiceCache resources.

Read more about envoy-cache-filter.