Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default cache question

    I've read a couple of articles on cache and setting expiration etc.
    What I can't find the answer to is - if you don't set an expiration for
    your cache, what is the default? And when your cache does expire, how
    do you catch this event? For example, if I have a datagrid which is
    populated by cached data and the cached data expires, what happens when
    I try to access that datagrid?


    Any help would be much appreciated.


    Cheers,

    Mike



    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Mike P Guest

  2. Similar Questions and Discussions

    1. Client-Side Cache Question
      Let's say I have a FLV that "lives" on a server, and I serve it up through, say, Ruby. The Ruby script takes care of obtaining the FLV from the...
    2. Cache?
      Hi I'm new to web services but have done a bit with web applications Is there a cache in web services as in web applications I want to read in...
    3. mm cache
      http://www.turcksoft.com/en/e_mmc.htm
    4. Cache object question
      Use HttpContext.Current.Cache. -- James J. Foster, DotNetCoders http://www.dotnetcoders.com "STom" <stombiztalker@hotmail.com> wrote in...
    5. lwp and dns cache
      I was wondering if there is anyway of having lwp cache its dns queries. What I am doing is getting dynamic data from various sites every five...
  3. #2

    Default Re: cache question

    the cache will expire when the aspnet_wp is forced to recycle

    when accessing cache data do something like this in a static method to
    retrieve the data

    string myCachedData = HttpContext.Current.WebCache("myCachedData");
    if ( myCachedData == null )
    {
    // code to put the data in the cache
    }
    return myCachedData;

    "Mike P" <mrp@telcoelectronics.co.uk> wrote in message
    news:uewfqPnVDHA.2352@TK2MSFTNGP12.phx.gbl...
    > I've read a couple of articles on cache and setting expiration etc.
    > What I can't find the answer to is - if you don't set an expiration for
    > your cache, what is the default? And when your cache does expire, how
    > do you catch this event? For example, if I have a datagrid which is
    > populated by cached data and the cached data expires, what happens when
    > I try to access that datagrid?
    >
    >
    > Any help would be much appreciated.
    >
    >
    > Cheers,
    >
    > Mike
    >
    >
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    PJ Guest

  4. #3

    Default Re: cache question

    What will cause aspnet_wp to recycle? Is it recycled when a session
    times out?

    Mike



    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Mike P Guest

  5. #4

    Default Re: cache question

    It is recycled when
    a) an application level error occurs
    b) the server is restarted (or IIS is restarted)
    c) an application times out, meaning it hasn't been accessed in the time
    out period
    d) in IIS 6.0 all applications are recycled on a set time period (set in
    the IIS manager). I beleive the default is 29 hours.
    e) If you recompile the application, when ASP.NET notices the change, it
    recycles the application


    Ryan Gregg

    "Mike P" <mrp@telcoelectronics.co.uk> wrote in message
    news:uOB52BoVDHA.652@tk2msftngp13.phx.gbl...
    > What will cause aspnet_wp to recycle? Is it recycled when a session
    > times out?
    >
    > Mike
    >
    >
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    Ryan Gregg Guest

  6. #5

    Default Re: cache question

    And I believe it happens when you modify the machine.config or web.config as
    well...

    "Ryan Gregg" <rgregg@wheatlandsystems.com> wrote in message
    news:ehXrBHrVDHA.1748@TK2MSFTNGP12.phx.gbl...
    > It is recycled when
    > a) an application level error occurs
    > b) the server is restarted (or IIS is restarted)
    > c) an application times out, meaning it hasn't been accessed in the
    time
    > out period
    > d) in IIS 6.0 all applications are recycled on a set time period (set
    in
    > the IIS manager). I beleive the default is 29 hours.
    > e) If you recompile the application, when ASP.NET notices the change,
    it
    > recycles the application
    >
    >
    > Ryan Gregg
    >
    > "Mike P" <mrp@telcoelectronics.co.uk> wrote in message
    > news:uOB52BoVDHA.652@tk2msftngp13.phx.gbl...
    > > What will cause aspnet_wp to recycle? Is it recycled when a session
    > > times out?
    > >
    > > Mike
    > >
    > >
    > >
    > > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > > Don't just participate in USENET...get rewarded for it!
    >
    >

    PJ Guest

  7. #6

    Default Cache question

    Via the -global.asax- file, on application startup,

    the following code does not work:

    System.Web.Caching.Cache.Insert (works on all other pages ...)

    whereas this works fine:

    HttpContext.Current.Cache.Insert

    Can anyone explain why this is so?
    Alvin K Guest

  8. #7

    Default Re: Cache question

    On application start there is no automatically mapped reference to the
    current Cache object.

    The object is handled through the HttpContext.Current.

    When you reference the Cache object (or session or application) on a page,
    you are in the HttpContext.Current by default.

    You will have to reference the Cache object through the HttpContext.Current
    outside of a direct request for a page. That goes for a web control library
    or anything else outside a page request.

    I have even had trouble with it when I created two threads in the same web
    request.

    bill


    "Alvin K" <asianx74@yahoo.com> wrote in message
    news:cd0e8b44.0307301239.3443d399@posting.google.c om...
    > Via the -global.asax- file, on application startup,
    >
    > the following code does not work:
    >
    > System.Web.Caching.Cache.Insert (works on all other pages ...)
    >
    > whereas this works fine:
    >
    > HttpContext.Current.Cache.Insert
    >
    > Can anyone explain why this is so?

    William F. Robertson, Jr. Guest

  9. #8

    Default Re: cache question

    So assigning something to the Cache is essentially the same as assigning
    it to a Session variable (i.e. it expires on timeout and is particular
    to the specific user and not the application)?


    Mike



    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Mike P Guest

  10. #9

    Default Re: cache question

    I've done a few tests and found that Cache is Application level and not
    Session level, which I would think means that it can only be used for
    storing global variables.


    Mike



    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Mike P Guest

  11. #10

    Default Cache Question

    I have a webpage written in the latest version of PHP and need a little bit
    of help with a rather pesky cache issue. Part of the source code is as
    follows:

    page.php
    <?
    echo "<meta http-equiv=pragma content=no-cache>";
    echo "<meta http-equiv=expires content='-1'>";
    Tony Tzankoff Guest

  12. #11

    Default Re: [PHP] Cache Question

    --- Tony Tzankoff <ttzankoff@medscripts.com> wrote:
    > I have a webpage written in the latest version of PHP and need
    > a little bit of help with a rather pesky cache issue. Part of
    > the source code is as follows:
    >
    > page.php
    > <?
    > echo "<meta http-equiv=pragma content=no-cache>";
    > echo "<meta http-equiv=expires content='-1'>";
    > echo "<embed src=filename.mp3 autostart=true>";
    > ?>
    >
    > The page does not cache (which is good), but the MP3 file does
    > (which is bad). Is there a way to NOT cache the MP3 file? I
    > would like to keep the file embedded within the page, if
    > possible. Thanks!
    In order to understand this behavior, you need to understand how the Web works,
    including a little bit about HTTP.

    First, as an aside note, if you are using PHP, there is absolutely no reason to
    set HTTP headers using the HTML meta tag. This is equivalent to the HTML in
    your example code:

    header('Pragma: no-cache');
    header('Expires: -1');

    Since Pragma is an HTTP/1.0 header, might I also suggest:

    header('Cache-Control: no-cache');

    Now, you are wondering how you can have all of these headers, yet the MP3 is
    still cached. That's because these headers are not sent when the MP3 is
    requested. The filename ends in .mp3, so PHP plays no role whatsoever (unless
    you have done something weird to force PHP to parse files ending in .mp3).

    When a Web clients sends the HTTP request for your page, it will receive
    something like this in the content of the response:

    <meta http-equiv=pragma content=no-cache>
    <meta http-equiv=expires content='-1'>
    <embed src=filename.mp3 autostart=true>

    Basically, the content is the output of your script, right? *This* is the stuff
    that won't get cached.

    Now, "filename.mp3" is just some text in the response at this point. There is
    no MP3 actually embedded into the HTML somehow. The browser parses the HTML and
    notices that it needs another resource, filename.mp3. Because there is no path
    specified, the browser will send a request for this resource using the same
    path as its parent (the page that is not going to be cached). The server will
    return this file in an HTTP response, and the headers in this response have
    nothing to do with your PHP script that was requested a few seconds ago. That
    is history.

    So, this is why the MP3 is cached while your HTML is not.

    Hope that helps.

    Chris

    =====
    Become a better Web developer with the HTTP Developer's Handbook
    [url]http://httphandbook.org/[/url]
    Chris Shiflett Guest

  13. #12

    Default Re: Cache Question

    Hi Tony,

    Chris explained a lot about this... I'm not an expert on this, but you might
    want to give a try to embed something like :

    "<embed src='mp3.php?mp3=filename' autostart=true>";

    And then let mp3.php send all of the no-cache headers together with the
    contents of the filename.mp3.

    It might work, I would give it a try...

    HTH,

    --
    Ivo

    "Tony Tzankoff" <ttzankoff@medscripts.com> wrote in message
    news:20030812152237.78650.qmail@pb1.pair.com...
    > I have a webpage written in the latest version of PHP and need a little
    bit
    > of help with a rather pesky cache issue. Part of the source code is as
    > follows:
    >
    > page.php
    > <?
    > echo "<meta http-equiv=pragma content=no-cache>";
    > echo "<meta http-equiv=expires content='-1'>";
    > .
    > .
    > .
    > echo "<embed src=filename.mp3 autostart=true>";
    > ?>
    >
    > The page does not cache (which is good), but the MP3 file does (which is
    > bad). Is there a way to NOT cache the MP3 file? I would like to keep the
    > file embedded within the page, if possible. Thanks!
    >
    >

    Ivo Fokkema Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139