Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Caching file stream?

Reply
Thread Tools

Caching file stream?

 
 
brett
Guest
Posts: n/a
 
      11-13-2006
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

 
Reply With Quote
 
 
 
 
Laurent Bugnion
Guest
Posts: n/a
 
      11-13-2006
Hi,

brett wrote:
> 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
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
 
Reply With Quote
 
 
 
 
Laurent Bugnion
Guest
Posts: n/a
 
      11-13-2006
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
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
 
Reply With Quote
 
brett
Guest
Posts: n/a
 
      11-13-2006
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

 
Reply With Quote
 
bruce barker \(sqlwork.com\)
Guest
Posts: n/a
 
      11-13-2006
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)


"brett" <> wrote in message
news: oups.com...
> 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
>



 
Reply With Quote
 
brett
Guest
Posts: n/a
 
      11-13-2006

bruce barker (sqlwork.com) wrote:
> 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/d...le.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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable page caching without disabling caching of jpegs andstylesheets etc JimLad ASP .Net 3 01-21-2010 10:13 AM
File Upload Without Caching Tim Haughton ASP .Net 2 11-18-2005 06:30 PM
SSI vs. reading in a file vs. caching a DB entry? darrel ASP .Net 5 01-04-2005 03:06 PM
Fragment Caching inside page caching? Troy Simpson ASP .Net 0 01-19-2004 11:57 AM
trouble with caching or caching the trouble Hypo ASP .Net 6 08-01-2003 07:11 AM



Advertisments