|
For an advanced hiera backends that open connections to a remote service it is not enough to simply throw away cached information as this may "leak connections". Just waiting for a GC to kick in and then expecting that it clears up a connection is not reliable and it may take a long time before such resources are freed. Depending on the implementation it may not even be freed until the ruby runtime is terminated.
The most natural would be to register a callback for a LookupContext cached key (or all keys). Using a lambda for this is however somewhat problematic if the backend is written in the Puppet Language as the lambda does not have access to the local scope it is defined in. It will work if the lookup context instance is given to it and if we document that this lambda only has access to the global scope + the lookup context given to it.
Preferably we would make a new implementation of Scope (that is not stupid), but that is a big thing.
Alternatives would be to register a named function that gets called with the lookup_context, or using name convention such that mymodule::mybackend::on_evict(lookupcontext) gets called. Neither is very nice.
In addition to being able to set the on-eviction-lambda there must be a way to get the already set lambda (to avoid setting it again).
Suggest using on_evict(&block) for setting it and on_evict() for getting it, and where on_evict(false) would drop the registered lambda.
|