Hi Trapulo,
Quote from Trapulo =============== =============== =============== ====
In fact, however, it can be good to have a copy either in memory and sql
server. But logging block retains in memory all data. If it can retain, for
example, last 100 objects in memory, and 10000 in sql, it will be great
(100
is too little to my requirenments, an 10000 is to big to leave in memory).
Instead of this, it has just a single parameter that sets memory and sql
cache.
=============== =============== =============== ====
As far as I know currently the enterprise library does not provide that
flexibility. The SQL data storage for the caching block is mainly used to
backup cached data in case in-memory cache is lost due to application
crash. It's not proposed as a primary cache.
To achieve your requirement we can write our own cache mechanism. The
pseudocode may be:
using System.Web.Cach ing;
public class MyCacheManager
{
private static Cache _cache = new Cache();
public static void AddCache(object data,object key)
{
if (_cache.Count 100)
{
//insert data to database
}
else
{
//add data to _cache
//optional, add a copy to database in case in-memory cache
is lost.
}
}
public static object GetCache(object key)
{
//if the data retrieved from _cache is null, access database
//if still no record retrieved, return null.
}
}
We can design a table to store the data and use SQL Server agent to remove
records every 7 days.
You can also consider using distributed caching. Though it's not the means
as you thought above it's another option that can increase performance.
http://www.codeplex.com/SharedCache
If you have further questions please feel free to ask.
Regards,
Allen Chen
Microsoft Online Community Support