Suppose a scenario where:
you need to execute an expensive operation which can fail or succeed.
the result of the operation is modeled by using a result object
Result<T>. The result object contains a boolean property which says if the operation succeeded and a property containing the operation result. Here you can find an example of such an implementation.you want to use Hybrid Cache to cache the result of the expensive operation by having all the good things provided by Hybrid Cache (e.g.: cache stampede protection).
you want to cache the operation result only if the operation succeeded. If the operation failed, you want to skip caching the operation result, so that the next time you can retry the operation.
Is there a simple and elegant way to do so by using the GetOrCreateAsync method provided by Hybrid Cache ? It seems to me that these requirements are not simple to match with the semantic of GetOrCreateAsync
A possible solution is using an exception to signal Hybrid Cache not to cache the result of a failed operation, as it is done here. Is there any other solution to this problem ?
It seems there is an api proposal on GitHub which goes in a similar direction.