Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Data Caching with SQL-XML & IIS

Author  Topic 

DManB
Starting Member

9 Posts

Posted - 2002-04-01 : 21:01:23
Does anyone know if the SQLXML add-on is capable
of caching data so that the web-browser wouldn't
requery the database ?

Looking for something similar to : Response.Expires = 600

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-04-01 : 21:06:46
Not natively. However you could write something in ASP that caches it in an application variable for a specified amount of time. There are a bunch of articles about this sort of thing in 4guysfromrolla.com

You can also come up with some generic routines to cache all sorts of stuff, it is a fun project to build.

Damian
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2002-04-02 : 04:18:31
What I've done in the past is send teh XML to the client, amnipulate the data with eitehr an activex control or javascript, and then send the XML back to the server to process changes. it's not easy, but damn nice on the users (and on yoru webservers) when you do.

Michael

Go to Top of Page

DManB
Starting Member

9 Posts

Posted - 2002-04-02 : 11:48:40
I was hoping to find a solution where the Browser Cache would
be used similar to images and html:

1. Browser needs file (from SRC attribute of some element)
2. Browser sends request with Cache Modified Date
3. My ASPX Page determines if the Browser's Cached version
can be used. If it can IIS would just send OK USE CACHE
or something like that.
4. If My ASPX page determines the cache is no good the
new version of XML is sent.

Any Thoughts ?

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-04-02 : 12:05:18
I found this on 4GuysFromRolla (probably what Merkin was talking about):

http://www.4guysfromrolla.com/webtech/032002-1.shtml

It's for classic ASP, but could probably work in a .Net environment. I also found this on the 4Guys .Net site:

http://aspnet.4guysfromrolla.com/articles/022802-1.aspx

Go to Top of Page

DManB
Starting Member

9 Posts

Posted - 2002-04-02 : 12:28:16
Already read it and watched video ... Doesn't deal with
Browser caching. Only server-side caching.

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-04-02 : 12:52:23
The only way I can think of this is if the XML data is stored in a file on the server and linked to the web page. The browser would be able to determine if the file has changed since it was last read, and use the cached version if applicable. Unfortunately I don't think this will actually work in practice, and there's no way for the web server to NOT get involved somehow. It would make sense only if there was a fixed set of data in the XML file, and that it was periodically updated (on demand updates would invalidate it each time).

This WOULD alleviate re-querying the database to some extent. You can pass some values, like timestamps, to the web server, and it can determine whether the query needs to be run again. The only problem I see with this is that it really doesn't solve anything. If the query is the same for two different calls, then it's already in SQL Server's cache(s), so the response will be pretty fast anyway. If the query has the same plan, but returns different data, the same will most likely apply; the plan is in cache, and enough data may be in cache for the query to be filled from it instead of disk. And last, if the query and data are different enough, you have to hit the database anyway.

What exactly do you need to cache on the browser side?

Go to Top of Page

DManB
Starting Member

9 Posts

Posted - 2002-04-02 : 13:33:04
Unfortunately I can't put the data in static XML files because it is different data for whoever is logged in and it must be secured to the Users ID (in Session variable).

Right now I am using an XML data island like so:
<XML SRC='VendorCombo.aspx'></XML>

The VendorCombo.aspx returns content type text/XML. I can even see the Cached version in the Internet Explorer temporary files. The application on the server will know when the User's Vendor list has changed by some code which stores the last modified date/time in the Application contents.

What I would like to do is return an OK TO USE CACHE or the NEW XML DATA. My problem is that I don't know how to : 1 - get the cached date & time transmitted from IE, and 2 - answer the request with an OK TO USE CACHE.

Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2002-04-02 : 14:31:04
What you could do is whatever event fires the "caching" have it check for the existance of sessionID.xml in some dir. If it's not there, create it and send that to the client. If it IS there, assume the client has the data already. That way, it's by user, you have a uniquie filename (so you should not run into collisions), and at teh end of the session kill any files with that sessionID associated with them.

Michael

Go to Top of Page

DManB
Starting Member

9 Posts

Posted - 2002-04-02 : 17:34:07
Problem with that is the XML file is not protected and there is the potential for someone to grab that file with confidential info. I was trying to use ASPX code to send XML because I can say something like:

GetVendorXML( Session("UserID") )

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-04-02 : 17:50:53
How do you feel about a code-behind page? I'm not up on the .Net versions of these, but I've done normal ASP versions of them.

Basically, you have a small browser frame that is not visible, but can be referenced from the main browser window using client-side script. Whenever the person browsing makes a request, it sends it to the code-behind window first. The code-behind page would simply accept a code or timestamp from the main window, and check with the web server quickly. If the web server replies, "OK", for example, then the main page won't need to reload. If the server says "Refresh" or something like that, then the main window will reload itself.

I've done this numerous times when I wanted portions of the web page to update, but not have the entire screen refresh. The code-behind window would pull the data, and I'd have a little client-side JavaScript to read that data and put it into the main window. As long as you work out a means to query the web server to figure out if and when a refresh is necessary, this is a really neat solution. You can even have the code-behind page on a timer, and have it check the web server periodically. No XML data is sent unless the refresh operation is detected. The code-behind page would only be sending 100 bytes or less of data, so network traffic is minimal.

Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-04-02 : 18:15:41
quote:

Already read it and watched video ... Doesn't deal with
Browser caching. Only server-side caching.





You never mentioned browser caching. You were talking about SQLXML. How were you planning on calling that at the browser ???

Damian
Go to Top of Page

DManB
Starting Member

9 Posts

Posted - 2002-04-02 : 20:10:32
quote:

You never mentioned browser caching. You were talking about SQLXML. How were you planning on calling that at the browser ???



Sorry ... this topic has grown as the days have past and I've thought about the problem some more... still no answer though.

Go to Top of Page

DManB
Starting Member

9 Posts

Posted - 2002-04-02 : 20:14:53
quote:

How do you feel about a code-behind page? I'm not up on the .Net versions of these, but I've done normal ASP versions of them.



Code-behind-pages in .NET is a way of handling ASP.NET events and page generation in a separate source-code file. In other words : separating your code from the html.... nothing like what you mention.

quote:

Basically, you have a small browser frame that is not visible, but can be referenced from the main browser window using client-side script. Whenever the person browsing makes a request, it sends it to the code-behind window first. The code-behind page would simply accept a code or timestamp from the main window, and check with the web server quickly. If the web server replies, "OK", for example, then the main page won't need to reload. If the server says "Refresh" or something like that, then the main window will reload itself.

I've done this numerous times when I wanted portions of the web page to update, but not have the entire screen refresh. The code-behind window would pull the data, and I'd have a little client-side JavaScript to read that data and put it into the main window. As long as you work out a means to query the web server to figure out if and when a refresh is necessary, this is a really neat solution. You can even have the code-behind page on a timer, and have it check the web server periodically. No XML data is sent unless the refresh operation is detected. The code-behind page would only be sending 100 bytes or less of data, so network traffic is minimal.



This isn't exactly what I'm trying to do.

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-04-02 : 20:41:50
quote:
This isn't exactly what I'm trying to do.

I understand that, but I cannot think of any way to do what you want. I wasn't suggesting a full code-behind page concept, the idea is that it's a secondary page, independent of the main page, that communicates with the server to determine when a data refresh is needed. This reduces your network traffic to a bare minimum.

Go to Top of Page

DManB
Starting Member

9 Posts

Posted - 2002-04-03 : 07:16:00
quote:

I understand that, but I cannot think of any way to do what you want. I wasn't suggesting a full code-behind page concept, the idea is that it's a secondary page, independent of the main page, that communicates with the server to determine when a data refresh is needed. This reduces your network traffic to a bare minimum.



Maybe as a last resort, but I seem to be getting closer. Thanks.

Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2002-04-03 : 12:00:21
DB Man,
Lets see if we can get a moer accurate version of your question.
Correct me if I'm wrong here.....

Question: I want to be able to download a set of data to a client (web browser) and I only want to download that data when it's out of date. The data is used to populate a Drop-Down box on a web page.

If I'm right about the question, I have a few questions for you.

1. Why is the data in a simple combo box worth caching? Is it a bunch of data in that box? Maybe you can do something to speed up the query that GETS the data? How long does it take for you to populate this combo box?

2. Can you use ActiveX controls? If so, you could write a control to do all of your caching, or you could write a "combo box" control that tries to read a "cached" datafile located on the local PC, or gets a new dataset from the web.

3. Could you use a cookie that stores the LastCachedDate and the XML you need in it, and then compare that date with something in your DB to determine of you need to recache? Then, if you need to recache, issue a new cookie?

Well solve this one way or another!
Michael


Go to Top of Page
   

- Advertisement -