Caching file stream?

B

brett

I read in text files based on the page a user has reqeusted. The files
are not larger than 10k. Sometimes I may read in two files for one
page but the total read doesn't exceed 15k. However, I'm doing this on
ever page load. After reading in the stream, I then do some parsing on
each text file and display the content in a Label control.

Is there a way to avoid doing the text file read and parsing on every
page load? The content is fairly static but I would like a way to
periodically refresh when something changes.

Thanks,
Brett
 
L

Laurent Bugnion

Hi,
I read in text files based on the page a user has reqeusted. The files
are not larger than 10k. Sometimes I may read in two files for one
page but the total read doesn't exceed 15k. However, I'm doing this on
ever page load. After reading in the stream, I then do some parsing on
each text file and display the content in a Label control.

Is there a way to avoid doing the text file read and parsing on every
page load? The content is fairly static but I would like a way to
periodically refresh when something changes.

Thanks,
Brett

Depending on how your users use your web application, a reasonable
approach would be to load the files in the Session object, only when the
Session is initialized. To do this, simply check the Session object and
look for the files' content. If it is not found, load them. In normal
circumstances, a Session won't last very long (though that may really
vary depending on what your app does). This will ensure that every time
that a user loads your app in a new browser instance, the files' content
is newly loaded.

Should that not be good enough, you can check a timestamp, and every
time that a certain time runs, reload the file on the next call. For
example, load the file in the Session object, and set a timestamp. On
each request, check the timestamp. If the delay is longer than what you
decide, reload the files.

HTH,
Laurent
 
L

Laurent Bugnion

Sorry, just noticed your thread name. Caching the stream is not a good
idea. It would imply leaving the stream open between the requests, and
that would block the file for any other client. Besides, I am not even
sure that it is possible, since each request runs in a different thread.
So caching the file stream is no good, but caching the file content is.

HTH,
Laurent
 
B

brett

Thanks Laurent. The timestamp approach sounds good but is there a way
to load by server session instead of user session? In other words,
rather than load the files into a session dependent on the user, I
could load into server memory and just provide it to each user.
Hopefully that makes sense. At some point, I could manuallly destroy
the file variable and recreate it for a refresh...if that's what I
want.

A little additional info: Users don't log in. This is just a simple
website.

Brett
 
B

bruce barker \(sqlwork.com\)

if you use the standard .net cache, you can set a file dependency, so the
cached item will be removed if the file changes.

-- bruce (sqlwork.com)
 
B

brett

bruce said:
if you use the standard .net cache, you can set a file dependency, so the
cached item will be removed if the file changes.

Thanks. This seems to be what I want minus what they are doing with
XML:
http://www.dotnetbips.com/articles/displayarticle.aspx?id=517
Does the CacheDependency class cache per user session or is it based on
a session that remains in memory as long as a user is on the server
(shared session amongst users).

Brett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top