I do not have an Azure account, so I cannot test this, but does this work in general? The linked question uses a MemoryCache
which is in-memory and probably references the added objects directly. As Azure cache is a distributed system, that will probably not work and the values need to be serialized in some way to be passed to the remote cache.
As I was writing this, I stumbled upon this SO question this SO question which clearly shows that Lazy<T>
is serializable and thus can probably be stored in Azure, but the value will be evaluated on serialization. Basically, using Lazy<T>
does not give you any advantage here, because of the aforementioned side-effect of putting it in the cache.
// We know for sure that the key exists at this point: // Two concurrent callers tried to get it, and this thread // happened to be deadlock victim.
That state is probably not true, because the cache item with that key might have expired between the exception and the call to Get
. Granted, that this is relatively unlikely and heavily depends on how small the cache timeout is, but it could happen. This scenario could be avoided if you retried the whole method upon receiving a DataCacheErrorCode.KeyAlreadyExists
error code.
I do not have an Azure account, so I cannot test this, but does this work in general? The linked question uses a MemoryCache
which is in-memory and probably references the added objects directly. As Azure cache is a distributed system, that will probably not work and the values need to be serialized in some way to be passed to the remote cache.
As I was writing this, I stumbled upon this SO question which clearly shows that Lazy<T>
is serializable and thus can probably be stored in Azure, but the value will be evaluated on serialization. Basically, using Lazy<T>
does not give you any advantage here, because of the aforementioned side-effect of putting it in the cache.
// We know for sure that the key exists at this point: // Two concurrent callers tried to get it, and this thread // happened to be deadlock victim.
That state is probably not true, because the cache item with that key might have expired between the exception and the call to Get
. Granted, that this is relatively unlikely and heavily depends on how small the cache timeout is, but it could happen. This scenario could be avoided if you retried the whole method upon receiving a DataCacheErrorCode.KeyAlreadyExists
error code.
I do not have an Azure account, so I cannot test this, but does this work in general? The linked question uses a MemoryCache
which is in-memory and probably references the added objects directly. As Azure cache is a distributed system, that will probably not work and the values need to be serialized in some way to be passed to the remote cache.
As I was writing this, I stumbled upon this SO question which clearly shows that Lazy<T>
is serializable and thus can probably be stored in Azure, but the value will be evaluated on serialization. Basically, using Lazy<T>
does not give you any advantage here, because of the aforementioned side-effect of putting it in the cache.
// We know for sure that the key exists at this point: // Two concurrent callers tried to get it, and this thread // happened to be deadlock victim.
That state is probably not true, because the cache item with that key might have expired between the exception and the call to Get
. Granted, that this is relatively unlikely and heavily depends on how small the cache timeout is, but it could happen. This scenario could be avoided if you retried the whole method upon receiving a DataCacheErrorCode.KeyAlreadyExists
error code.
I do not have an Azure account, so I cannot test this, but does this work in general? The linked question uses a MemoryCache
which is in-memory and probably references the added objects directly. As Azure cache is a distributed system, that will probably not work and the values need to be serialized in some way to be passed to the remote cache.
As I was writing this, I stumbled upon this SO question which clearly shows that Lazy<T>
is serializable and thus can probably be stored in Azure, but the value will be evaluated on serialization. Basically, using Lazy<T>
does not give you any advantage here, because of the aforementioned side-effect of putting it in the cache.
// We know for sure that the key exists at this point: // Two concurrent callers tried to get it, and this thread // happened to be deadlock victim.
That state is probably not true, because the cache item with that key might have expired between the two callsexception and the call to Get
. Granted, that this is relatively unlikely and heavily depends on how small the cache timeout is, but it could happen. This scenario could be avoided if you retried the whole method upon receiving a DataCacheErrorCode.KeyAlreadyExists
error code.
I do not have an Azure account, so I cannot test this, but does this work in general? The linked question uses a MemoryCache
which is in-memory and probably references the added objects directly. As Azure cache is a distributed system, that will probably not work and the values need to be serialized in some way to be passed to the remote cache.
As I was writing this, I stumbled upon this SO question which clearly shows that Lazy<T>
is serializable and thus can probably be stored in Azure, but the value will be evaluated on serialization. Basically, using Lazy<T>
does not give you any advantage here, because of the aforementioned side-effect of putting it in the cache.
// We know for sure that the key exists at this point: // Two concurrent callers tried to get it, and this thread // happened to be deadlock victim.
That is probably not true, because the cache item with that key might have expired between the two calls to Get
. Granted, that this is relatively unlikely and heavily depends on how small the cache timeout is, but it could happen. This scenario could be avoided if you retried the whole method upon receiving a DataCacheErrorCode.KeyAlreadyExists
error code.
I do not have an Azure account, so I cannot test this, but does this work in general? The linked question uses a MemoryCache
which is in-memory and probably references the added objects directly. As Azure cache is a distributed system, that will probably not work and the values need to be serialized in some way to be passed to the remote cache.
As I was writing this, I stumbled upon this SO question which clearly shows that Lazy<T>
is serializable and thus can probably be stored in Azure, but the value will be evaluated on serialization. Basically, using Lazy<T>
does not give you any advantage here, because of the aforementioned side-effect of putting it in the cache.
// We know for sure that the key exists at this point: // Two concurrent callers tried to get it, and this thread // happened to be deadlock victim.
That state is probably not true, because the cache item with that key might have expired between the exception and the call to Get
. Granted, that this is relatively unlikely and heavily depends on how small the cache timeout is, but it could happen. This scenario could be avoided if you retried the whole method upon receiving a DataCacheErrorCode.KeyAlreadyExists
error code.
I do not have an Azure account, so I cannot test this, but does this work in general? The linked question uses a MemoryCache
which is in-memory and probably references the added objects directly. As Azure cache is a distributed system, that will probably not work and the values need to be serialized in some way to be passed to the remote cache.
As I was writing this, I stumbled upon this SO question which clearly shows that Lazy<T>
is serializable and thus can probably be stored in Azure, but the value will be evaluated on serialization. Basically, using Lazy<T>
does not give you any advantage here, because of the aforementioned side-effect of putting it in the cache.
// We know for sure that the key exists at this point: // Two concurrent callers tried to get it, and this thread // happened to be deadlock victim.
That is probably not true, because the cache item with that key might have expired between the two calls to Get
. Granted, that this is relatively unlikely and heavily depends on how small the cache timeout is, but it could happen. This scenario could be avoided if you retried the whole method upon receiving a DataCacheErrorCode.KeyAlreadyExists
error code.