Open
Description
Context
Some applications / libraries perform (heavy) calculations on the service bindings returned from the ServiceBindingAccessor
.
For example, service bindings should be transformed into an application internal representation.
To safe computational overhead, applications may want to cache their internal objects instead of doing the transformation each and every time when they access ServiceBindingAccess#getBindings
.
Unfortunately, by doing so, application might be out of sync with the actual service bindings.
Request
It would be great if applications would get notified whenever a new set of service bindings is created / returned by a ServiceBindingAccessor
instance.
Suggestions
Workaround proposal:
@RequiredArgsConstructor
class ServiceBindingTransformer {
@Nonnull
private final ServiceBindingAccessor delegate;
@Nullable
private List<ServiceBinding> lastServiceBindings;
@Nullable
private List<MyTransformedServiceBinding> transformedBindings;
@Nonnull
public List<MyTransformedServiceBinding> getTransformedBindings()
{
final List<ServiceBinding> currentServiceBindings = delegate.getServiceBindings();
if (currentServiceBindings != lastServiceBindings || transformedBindings == null)
{
// this will only be done in case the bindings were not served from a cache
transformedBindings = transformBindings(currentServiceBindings);
lastServiceBindings = currentServiceBindings;
}
return transformedBindings;
}
private List<MyTransformedServiceBinding> transformBindings(@Nonnull final List<ServiceBinding> bindings)
{
// TODO: implement me
}
}
private static class MyTransformedServiceBinding {
}
Questions
- How do we solve the multi-level caching? (e.g. K8s file system cache and simple cache)