Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caching in a console application

I need to cache a generic list so I dont have to query the databse multiple times. In a web application I would just add it to the httpcontext.current.cache . What is the proper way to cache objects in console applications?

like image 471
Tom Squires Avatar asked Sep 29 '11 15:09

Tom Squires


People also ask

What is caching in application?

Caching Definition It saves data for software applications, servers, and web browsers, which ensures users need not download information every time they access a website or application to speed up site loading.

What is caching in C#?

Caching enables you to store data in memory for rapid access. When the data is accessed again, applications can get the data from the cache instead of retrieving it from the original source. This can improve performance and scalability.

When should you use cache memory?

An in-memory cache removes the performance delays when an application built on a disk-based database must retrieve data from a disk before processing. Reading data from memory is faster than from the disk. In-memory caching avoids latency and improves online application performance.


1 Answers

Keep it as instance member of the containing class. In web app you can't do this since page class's object is recreated on every request.

However .NET 4.0 also has MemoryCache class for this purpose.

like image 191
Muhammad Hasan Khan Avatar answered Oct 15 '22 14:10

Muhammad Hasan Khan