alastairtree / LazyCache

An easy to use thread safe in-memory caching service with a simple developer friendly API for c#
https://nuget.org/packages/LazyCache
MIT License
1.72k stars 159 forks source link

WebApi and LazyCache issue #19

Closed IrvinDominin closed 7 years ago

IrvinDominin commented 7 years ago

Hi @alastairtree ,

In my webapi I'm calling LazyCache in order to cache some consumed webservices.

At the moment I see a cache, but the webmethods are not called.

Here is my code:

        private Func<int, OBJDON> SWEB_CryptoClientCall = (x) =>
        {
            OBJDON resultDom = new OBJDON();

            using (PyAuth SERVIZIO = new PyAuth())
            {
                resultDom = SERVIZIO.PY_GET_DATA("", 0, 1, x, 0);
            }

            return resultDom;
        };

The call:

            OBJDON resultDom = new OBJDON();

            resultDom = cache.GetOrAdd($"SWEB_{cryptoString}", () => SWEB_CryptoClientCall((int)CUR_UTE), DateTimeOffset.Now.AddDays(1));

resultDom is always null and the function is not fired. What am I doing wrong?

IrvinDominin commented 7 years ago

A colleague used the same key for another entity eletewhere, solved, now works flawlessly

alastairtree commented 7 years ago

Was going to say that code looks fine to me. Thanks for closing.