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 Do I Add LazyCache to an Existing Web Forms Application? #137

Closed PostAlmostAnything closed 4 years ago

PostAlmostAnything commented 4 years ago

I just installed LazyCache via Nuget Package Manager in Visual Studio for an old ASP.Net Web Forms application, but cannot find any examples of how to use LazyCache beyond installing it. All of the examples you use involve EF and most of them are on .Net Core applications. Yet you claim to support .Net Framework applications.

How do I add LazyCache support for my existing Web Services(.asmx), Table Adapters(.xsd), and SqlDataSource controls? This old design does not use Entity Framework or MVC.

PostAlmostAnything commented 4 years ago

The application currently uses .Net Framework 4.7.2

PostAlmostAnything commented 4 years ago

Looks like I can add LazyCache to the .cs files associated with the .asmx files after they pull lists of data from the .xsd fileds. It works much faster, but I would like to know how often the cache is reset. One of the web services is a list of search suggestions for an autocomplete extender from the AJAX Control Toolkit which gets its suggestions from tags in individual posts and I don' want them to get too outdated.

alastairtree commented 4 years ago

LazyCache 2 targets netstandard2 so will work fine in current versions of full framework. If using earlier. Net Framework versions you will need to use LazyCache 0.7. The readme had exact details of compatibility between versions.

The sample app in this repo targets full framework, but uses MVC rather than web forms.

To use it in webforms just instantiate a ‘new CachingService()‘ in code-behind and you will get a reference to the default shared cache, or you can use a dependency injection service and obtain a reference to IAppCache.

The defaults are to cache for 20m and then expire. This default can be changed, or you can change how long to cache each item specifically using the API as you insert the item. The wiki in this repo had lots of docs showing how.

Let me know if you have any other questions, and please close this issue once you have solved your problem.

alastairtree commented 4 years ago

Am closing for now, but can reopen later if required. Thanks,