Caching file stream?

Discussion in 'ASP .Net' started by brett, Nov 13, 2006.

  1. brett

    brett Guest

    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
     
    brett, Nov 13, 2006
    #1
    1. Advertising

  2. 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
     
    Laurent Bugnion, Nov 13, 2006
    #2
    1. Advertising

  3. 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
     
    Laurent Bugnion, Nov 13, 2006
    #3
  4. brett

    brett Guest

    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
     
    brett, Nov 13, 2006
    #4
  5. 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:...
    > 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
    >
     
    bruce barker \(sqlwork.com\), Nov 13, 2006
    #5
  6. brett

    brett Guest

    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/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
     
    brett, Nov 13, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hypo
    Replies:
    6
    Views:
    460
  2. Troy Simpson

    Fragment Caching inside page caching?

    Troy Simpson, Jan 19, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    843
    Troy Simpson
    Jan 19, 2004
  3. Replies:
    9
    Views:
    671
    Alex Buell
    Apr 27, 2006
  4. Guest
    Replies:
    1
    Views:
    374
    bruce barker
    Jun 16, 2007
  5. JimLad
    Replies:
    3
    Views:
    948
    JimLad
    Jan 21, 2010
Loading...

Share This Page