If a trusted dictionary is intended to be used as a cache, then I really see no reason to unload unused items in Azure Storage. If this is a cache, I would expect that the unused elements will be cleared, and the caller will need to return to the source of truth for anything that has expired from the cache. But it looks like you want a reliable dictionary to be the last source of truth. Therefore, I think that you need to first decide whether you are really creating a cache, or a source of a true data store that can output data from memory. This is more like the latter.
In any case, this can be done as you described, but it is not easy to synchronize them sequentially, because you do not have a transaction through a reliable dictionary and an external store.
Enumerating the collection is fine, but it is an expensive operation, so I would not recommend doing this on large amounts of data in a hot way, for example, on a user request path. It is normal to do this periodically in a planned manner.
Need to offload data to external storage? Can you offload the local disk? Trusted collections will soon automatically dump the state to disk.
source share