You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The existing cache relies on a single criteria to invalidate an
entry: if the ReadHandle<T> cannot be "entered", then it is invalid
and the provider needs to be asked for a refresh; which may fail or
not, depending on whether a factory for the key exists or not.
This behavior suffices to invalidate entries (read handles) when
the wrapped objects are removed or created in the provider. However,
providers (and hence caches) may have "alias" keys. An example is
a Fib object that can be identified by both an Id (master key) but
also a Vni. In such a case, the cache may itself have two cached
entries, pointing to the same readhandle. So far so good. However,
if such aliases get exchanged without the objects being torn down,
they will remain in the cache indefinitely, pointing to the wrong
object, because they will not be invalidated. In the example of a
Fib, suppose 2 Fibs with ids A and B. A is accessible via vni 10
and B only with its Id. At some point, there is a configuration
change such that Fib A no longer uses vni 10, but B is assigned
vni 10, and both Fibs continue to exist.Without a mechanism to
invalidate the entry with key vni = 10, the cache would return
a readhandle for A instead of B.
Invalidating such entries (vni 10 -> Rhandle(A)) can be tricky
because we don't want to poll the provider for a handle every time
(which would defeat the whole point of the cache) and because the
provider itself may be wrapped in left-right, meaning that
changes may not immediately appear in readers. Some mechanism is
needed to be able to tell if a cached entry points to the "right"
object, or has to be otherwise invalidated / refreshed.
This patch augments the implementation to address that case by:
- defining the identity of a T (in ReadHandle<T>) with a trait
- augmenting cached entries to store that identity, which may
differ from the key used to access them
- invalidating entries by detecting if their identity has
changed. This is achieved by comparing the "cached identity"
(the identity the cache believes the object accessed via the
readhandle has) against the identity it sees when accessing
the object.
The only additional requirement is implementing trait Identity for
T.
Signed-off-by: Fredi Raspall <[email protected]>
0 commit comments