question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cache policy gives unhelpful exception on sync/async config/execution mismatch

See original GitHub issue

I am following the samples to implement cache but I’m getting an exception during the call:

This is the policiy definition:

var cachePolicy = Policy.Cache(new MemoryCacheProvider(MemoryCache.Default), TimeSpan.FromMinutes(5))

Then this is the call:

return cachePolicy.ExecuteAsync(async () => await _webService.someMethodAsync());

And this is the error it throws:

Value cannot be null. Parameter name: nonGenericCacheProvider" at Polly.Caching.GenericCacheProviderAsync'1..ctor(IAsyncCacheProvider nonGenericCacheProvider)

What am I missing? I think this pretty much matches the samples offered in the Readme.md, but still no idea how to get rid of that exception.

BTW: the ExecuteAsync overload to set Context and set the operationKey shows as deprecated, something not mentioned in documentation.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
reisenbergercommented, May 26, 2018

@CesarD For asynchronous executions using ExecuteAsync(...), the policy must be defined as an asynchronous policy, thus:

var cachePolicy = Policy.CacheAsync(new MemoryCacheProvider(MemoryCache.Default), TimeSpan.FromMinutes(5));

All policies should give a helpful exception message explaining that, if sync/async are mixed incorrectly, but this case has escaped that. I’ll fix to make sure it gives a helpful exception.

Thanks for spotting the deprecated overload quoted in the cache documentation: it’ll be corrected in both the readme and wiki.

1reaction
reisenbergercommented, May 29, 2018

@CesarD Thanks for the feedback. Extra clarification added:

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found