468,115 Members | 2,068 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,115 developers. It's quick & easy.

persistent cache in SQL Server

Hello,
I'm developing an asp.net application that is connected to a remote system
using WCF (wshttp binding). So I want to use a local cache to manage data
that I receive from remote service.

I'm using caching block from MS application enterprise library 4.1,
configured to use a SQL Server cache. That's great: it works with very
little effort.
However I noticed that caching block mantains a copy of the cache in memory
(loading all cache when it starts). I want to matain data only in SQL
Server, because are very large data that I mantain in cache for a lot of
time (about 7 days). Is there any way I can use ONLY the SQL Server
repository instead of in.memory AND Sql Server?

thanks


Nov 14 '08 #1
5 2487
The idea behind cache, as MS has it, is to save time getting information by
putting it in memory. SQL is there as a backup, but it is not designed to be
a primary mechanism, as SQL retrievals are slower than memory. If you want
to store long term temporary infomration in SQL and not really cache,
consider rolling your own mechanism rather than use the MS cache bits, as
you are not really caching here.

--
Gregory A. Beamer
MVP: MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think Outside the Box! |
********************************************
"Trapulo" <tr******@noemail.noemailwrote in message
news:DF**********************************@microsof t.com...
Hello,
I'm developing an asp.net application that is connected to a remote system
using WCF (wshttp binding). So I want to use a local cache to manage data
that I receive from remote service.

I'm using caching block from MS application enterprise library 4.1,
configured to use a SQL Server cache. That's great: it works with very
little effort.
However I noticed that caching block mantains a copy of the cache in
memory (loading all cache when it starts). I want to matain data only in
SQL Server, because are very large data that I mantain in cache for a lot
of time (about 7 days). Is there any way I can use ONLY the SQL Server
repository instead of in.memory AND Sql Server?

thanks

Nov 15 '08 #2
Yes: I need a cache that saves time getting data from remote WCF Server,
instead of saving data from getting data from SQL Server. So SQL is a lot
faster that a remote WCF call and I need a "real cache"...

Is there some ready library I can use someone can suggest? I not want to
write my own code to have a very common scenario...

thanks

"Gregory A. Beamer" <No************@comcast.netNoSpamMwrote in message
news:uP**************@TK2MSFTNGP02.phx.gbl...
The idea behind cache, as MS has it, is to save time getting information
by putting it in memory. SQL is there as a backup, but it is not designed
to be a primary mechanism, as SQL retrievals are slower than memory. If
you want to store long term temporary infomration in SQL and not really
cache, consider rolling your own mechanism rather than use the MS cache
bits, as you are not really caching here.

--
Gregory A. Beamer
MVP: MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think Outside the Box! |
********************************************
"Trapulo" <tr******@noemail.noemailwrote in message
news:DF**********************************@microsof t.com...
>Hello,
I'm developing an asp.net application that is connected to a remote
system using WCF (wshttp binding). So I want to use a local cache to
manage data that I receive from remote service.

I'm using caching block from MS application enterprise library 4.1,
configured to use a SQL Server cache. That's great: it works with very
little effort.
However I noticed that caching block mantains a copy of the cache in
memory (loading all cache when it starts). I want to matain data only in
SQL Server, because are very large data that I mantain in cache for a lot
of time (about 7 days). Is there any way I can use ONLY the SQL Server
repository instead of in.memory AND Sql Server?

thanks

Nov 17 '08 #3
Hi Trapulo,

From your description you want to store the data into SQL Server that is
retrieved from WCF, right? If so, as Gregory said, it's not a cache.

First I need to confirm if you need a global data structure or a
user-independent data structure. If the data is user independent I suggest
you use the ASP.NET Session. As we know, session can be stored in SQL
Server:

http://support.microsoft.com/kb/317604

You can call WCF method and store the retrieved data into Session.
If it's global data you can design a table:

Key P.K.
Value
TimeStamp

Then store the retrieved data into database and use Sql Server Agent
Service to remove the expired records every 7 days.

Please let me know if you have any questions.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 18 '08 #4
"Allen Chen [MSFT]" <v-******@online.microsoft.comwrote in message
news:qx**************@TK2MSFTNGHUB02.phx.gbl...
Hi Trapulo,

From your description you want to store the data into SQL Server that is
retrieved from WCF, right? If so, as Gregory said, it's not a cache.
Yes
However I think it's sure a cache

http://en.wikipedia.org/wiki/Cache:
"In computer science, a cache (pronounced /kæʃ/) is a collection of data
duplicating original values stored elsewhere or computed earlier, where the
original data is expensive to fetch (owing to longer access time) or to
compute, compared to the cost of reading the cache"
First I need to confirm if you need a global data structure or a
user-independent data structure
global data.
If the data is user independent I suggest
you use the ASP.NET Session. As we know, session can be stored in SQL
Server:

http://support.microsoft.com/kb/317604

You can call WCF method and store the retrieved data into Session.
this can be interesting. However, as I said, data are global
If it's global data you can design a table:

Key P.K.
Value
TimeStamp

Then store the retrieved data into database and use Sql Server Agent
Service to remove the expired records every 7 days.

Please let me know if you have any questions.
Ok thanks.
I was hoping to find a full featured complete library (as logging block).
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. Is there any easy way we can extend logging block to have this goal?

thanks

Nov 18 '08 #5
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.Caching;

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

Nov 20 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Felix E. Klee | last post: by
16 posts views Thread by Paul Rubin | last post: by
2 posts views Thread by DartmanX | last post: by
1 post views Thread by Jeff | last post: by
1 post views Thread by Ryan | last post: by
reply views Thread by Roger | last post: by
5 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.