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

How to disable the cache #94

Closed nicostubi closed 4 years ago

nicostubi commented 5 years ago

Hello,

Isn't there a simple way to disable the cache?

The only thing I can think of is, to set a DefaultCachePolicy.DefaultCacheDurationSeconds = 0

Best, Nico

alastairtree commented 4 years ago

The easiest way would be to swap out the CachingService implementation of IAppCache for MockMemoryCache. This could be done during application startup if you are using dependency injection.

Using the mock is the same approach you would often use in unit tests, so have a look at https://github.com/alastairtree/LazyCache/wiki/Unit-testing-code-using-LazyCache .

nicostubi commented 4 years ago

And what would be the advantage compared to my solution above?

Mocking is great for unit tests, not really for production code.