-2

I am trying to use Akavache's BlobCache.InMemory.GetOrCreateObject to add caching to one of my database table, when I call it asynchronously, everything is fine. But since async requires caller to change to async as well and there are a lot of places to change, so I opt to call BlobCache.InMemory.GetOrCreateObject synchronously instead by doing something like below

public async Task<List<T>> GetAllDataAsync() => await BlobCache.InMemory.GetOrCreateObject(...);
public List<T> GetAllData() => GetAllDataAsync().Result;

This will cause deadlock. What have I done wrong?

Edit1: This code is running in a ASP.NET Web API

imgen
  • 2,803
  • 7
  • 44
  • 64
  • 2
    There are hundreds of questions regarding deadlocks due to using `.Result`, did you even search? A common solution is to use `GetAllDataAsync().GetAwaiter().GetResult()`, but this depends also on the `SynchronizationContext` but you did not add information on where this is being run. – Camilo Terevinto Nov 23 '17 at 09:55
  • embrace doing it all async or doing it all with Observables and you will have a much happier time :-) – Shane Neuville Nov 23 '17 at 16:00

1 Answers1

2

Akavache is designed for mobile and desktop applications and will perform very poorly in a server environment. Use Redis or memcached.

Ana Betts
  • 73,868
  • 16
  • 141
  • 209