Solved

SQL 2008 CLR Trigger to update memory cache in ASP.NET application

Posted on 2010-09-21
4
959 Views
Last Modified: 2012-05-10
Hello All,

I have a web page (ASP.NET)  requesting constantly data from the server by querying db.

Problem is that there are lots of requests and db is heavily loaded by the queries.

So I was thinking about creating static list (some kind of cache) inside ASP.NET app.  containing record from queried table.
All the requests would read directly from that cache.
Now I need a good way to update list after update is done on db. table.

I was thinking about CLR trigger with some remoting to ASP.NET app.

However it's quite complex (not even sure how to do it yet) maybe some of you has a better (easier) solution?

I'm using .NET 4.0, SQL 2008 Web ed.

Thanks a lot for any ideas
0
Comment
Question by:kheim2008
  • 2
4 Comments
 
LVL 11

Expert Comment

by:Larissa T
ID: 33729728
I depends what type of information you want to save in this "cache" and how often it needs is changed, and how fresj it needs to be

One generic option would be;
define each of your "cached" objects in DB as table with columns  cacheID (unique), loadDate, updateDate, plus some other metadata, for example list of tables/columns it depends on

All updates in you database need update "updateDate" when one of the objects that define your cache is updated.

In your application, before you read data from cache you will to get cacheID.updateDate  from database, compare it  with date in application cache, and use data from memory  or update cached object from DB if dates are different before you use it.


There are many variation depending on how often your update data and how fresh data your application needs. In this case you can just update cache on demand or by schedule.
0
 

Author Comment

by:kheim2008
ID: 33729868
I'm afraid that updates happens too often to query for the updates every time.
I think CLR trigger is the solution - my main question is what is the best way to "transfer" CLR trigger data into ASP.NET app.
0
 
LVL 11

Accepted Solution

by:
Larissa T earned 500 total points
ID: 33730324
If updates happens too often, your design can produce more load on database, then just running queries. In addition to that you need to worry about synchronization.
In other words you are trying to create  copy of database inside your .NET application and updated this copy anytime database is updated.

You may better spend you time optimizing queries and DB design
Here are details about CLR triggers with samples.
http://msdn.microsoft.com/en-us/library/ms131093.aspx
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question