Skip to content

Proposal: Allow Setting Cache Miss Policy in Cache Options #2397

Closed
@stevekuznetsov

Description

@stevekuznetsov

Today, when a user gets a client.Client from a Manager (with mgr.GetClient()), they get a cache-backed client that has some surprising behavior - when a cache miss occurs, an informer is spun up to feed data into the cache. This means that one client.Get() call for one resource will, by default, start a cluster-scoped watch on all objects of that type and keep them in memory forever. While this is an understandable way for the cache to work, I've seen it bite folks who did not expect this behavior. While I don't think that this should be the default, at a minimum I'd love to see the cache miss policy be configurable at creation time so that folks can opt out of this behavior. Today it is possible to opt out of caching particular resources, but that's done with a hard-coded deny-list, which means if you ever forget to update that list, you get bitten.

I'd like to propose adding a new field in the cache.Options:

// pkg/cache/cache.go

// Options are the optional arguments for creating a new InformersMap object.
type Options struct {
    // ...
    
    // MissPolicy determines how the cache should behave when a Get finds no
    // entry in the cache or a List captures no items. See the CacheMissPolicies for
    // documentation for each policy.
    MissPolicy CacheMissPolicy
}

type CacheMissPolicy string

const (
    // Forward configures the cache to forward a cache miss to the client, unchanged,
    // meaning that the client gets an errors.NotFound for a Get and an empty response
    // for a List.
    Forward CacheMissPolicy = "forward"

    // Backfill configures the cache to spin up an informer for a resource when the first
    // request for that resource comes in. This means that a Get or a List may take longer
    // than normal to succeed on the first invocation as the cache waits until it's fully back-
    // filled.
    Backfill CacheMissPolicy = "backfill"

    // LiveLookup configures the cache to issue a live client call to the server for requests
    // that do not correspond to resources that have been explicitly configured to be cached.
    LiveLookup CacheMissPolicy = "liveLookup"
)

We can keep the default as "backfill" to not change behavior.

/cc @alvaroaleman @vincepri

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions