-
Notifications
You must be signed in to change notification settings - Fork 53
Opni Plugins
Alexandre Lamarre edited this page Apr 18, 2023
·
1 revision
TODO
TODO
The caching provider helps cache RPCs between GRPC services. It is a Client-side caching mechanism.
- A cache provider is set for the plugin, see below.
- The method you wish to cache must have a request that is cacheable, which requires one of :
- Implementing
pkg/caching/CacheKeyer
interface - Registering the request type
func RegisterProtoType(msg proto.Message, f func(msg protoreflect.ProtoMessage) string)
atinit
time
- Implementing
System plugins provide a method UseCachingProvider(c caching.CachingProvider[proto.Message])
that lets you access the underlying cache, and set the cache provider.
func (p *Plugin) UseCachingProvider(c caching.CachingProvider[proto.Message]) {
c.SetCache(caching.NewInMemoryGrpcTtlCache(50*1024*1024, time.Minute))
}
By default no responses are cached unless opted into.
- wrapping a request context with
WithGrpcClientCaching(ctx context.Context, d time.Duration)
:
clusterList, err := mgmtClient.ListClusters(
caching.WithGrpcClientCaching(ctx, 1*time.Minute),
&managementv1.ListClustersRequest{},
)
-
WithBypassCache
forcefully invalidates the cache :
clusterList, err := mgmtClient.ListClusters(
caching.WithBypassCache(ctx),
&managementv1.ListClustersRequest{},
)
- Servers are also free to force clients to cache their responses if the server method uses
ForceClientCaching(ctx context.Context, ttl time.Duration)
. Note thatWithBypassCache
does not respect this directive:
func (c *SimpleServer) GetValueWithForcedClientCaching(ctx context.Context, _ *emptypb.Empty) (*Value, error) {
c.mu.Lock()
defer c.mu.Unlock()
caching.ForceClientCaching(ctx, c.cacheMaxAge)
return &Value{
Value: c.value,
}, nil
}
TODO
Architecture
- Backends
- Core Components