Is there a way to Clear - - - - OutputCache ?

Last post 11-28-2006 11:16 AM by waynelambright. 6 replies.

Sort Posts:

  • Is there a way to Clear - - - - OutputCache ?

    11-22-2006, 2:24 PM
    • Loading...
    • waynelambright
    • Joined on 05-23-2006, 11:26 PM
    • San Francisco
    • Posts 20

    Hello,

    I'm using the OutputCache

    <%@ OutputCache Duration="600" VaryByHeader="UserAgent" VaryByParam="none" %>

     

    I’m using the OutputCache on my review web site (http://sfsurvey.com)and I would like to dump the cache when a new review is posted.

    How can I programicaly tell it to dump the cache?  Its only one page being cache so there are no paramatrized versions do dump.

     
    Thanks for your help.
     

    Wayne Lambright 


     

    Wayne Lambright
    http://lambright.com
    415-750-1921 GMT-8 Pacific
    Filed under: ,
  • Re: Is there a way to Clear - - - - OutputCache ?

    11-22-2006, 2:34 PM
    Darrell Norton, MVP
    Darrell Norton's Blog


    Please mark this post as answered if it helped you!
  • Re: Is there a way to Clear - - - - OutputCache ?

    11-22-2006, 3:06 PM
    • Loading...
    • waynelambright
    • Joined on 05-23-2006, 11:26 PM
    • San Francisco
    • Posts 20

    thanks for the tip, what would the code look like?

    I have two pages, one where reviews are posted, and one where they are displayed.

     

    post.aspx

    display.aspx

    after a post, I would like to flush the cache on the display.aspx page.

     I had considered

     

    post.aspx?flush=1  which would trigger the flushing. 

     

    if request("flush")="1" then

    'code to flush cache goes here...


    end if

     
    any help would be apreciated.

    thanks

    wayne

     

     

    Wayne Lambright
    http://lambright.com
    415-750-1921 GMT-8 Pacific
    Filed under:
  • Re: Is there a way to Clear - - - - OutputCache ?

    11-22-2006, 3:29 PM
    • Loading...
    • waynelambright
    • Joined on 05-23-2006, 11:26 PM
    • San Francisco
    • Posts 20

     

    I tried this but it does not seem to work.

    if request("flush")="1" then

        Dim path As String
        path="/display.aspx"
        HttpResponse.RemoveOutputCacheItem(path)

    end if

    Wayne Lambright
    http://lambright.com
    415-750-1921 GMT-8 Pacific
    Filed under:
  • Re: Is there a way to Clear - - - - OutputCache ?

    11-24-2006, 4:11 PM
    • Loading...
    • waynelambright
    • Joined on 05-23-2006, 11:26 PM
    • San Francisco
    • Posts 20

    DarrellNorton:

     

    Hello Darren

     I tried that but it does not work. 

     
    try the code yourself.

     

    <%@ Page Language="VB"  Debug="true"  ContentType="text/html" ResponseEncoding="iso-8859-1" %>
    <%@ OutputCache Duration="3600" Location="Server"  VaryByParam="none" %>
    <%
    if request("w")="1" then

        Dim path As String
        path="/default_C.aspx"
        HttpResponse.RemoveOutputCacheItem(path)
    end if
    %>
    <head>
    <title>cache clear</title>
    </head>
    <body>

     <a href="?w=1">click to clear cache</a> <h1><%=Now()%></h1>
     
     
    </body>
    </html>
     

    Wayne Lambright
    http://lambright.com
    415-750-1921 GMT-8 Pacific
    Filed under: ,
  • Re: Is there a way to Clear - - - - OutputCache ?

    11-28-2006, 1:37 AM
    • Loading...
    • GeorgeZ
    • Joined on 11-16-2006, 6:09 AM
    • UpC
    • Posts 552

    Hi,

    The page cannot remove it's own cache because it was already Cached itself. You need another page to clear the page's Output Cache

    Here is my working sample code:

    1. OutputCached.aspx

    <%@ Page Language="VB"  Debug="true"  ContentType="text/html" ResponseEncoding="iso-8859-1" %>
    <%@ OutputCache Duration="3600" Location="Server"  VaryByParam="none" %>

    <html>
    <head>
    <title>This page is from OutputCache</title>
    </head>
    <body>

    <h1><%=Now()%></h1>
     
     
    </body>
    </html>

    2. ClearOutputCache.aspx

    <%@ Page Language="VB"  Debug="true"  ContentType="text/html" ResponseEncoding="iso-8859-1" %>
    <script runat="server">  

        Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

         Dim path As String
         path="/AbosoluteVitualPath/OutputCached.aspx"
         HttpResponse.RemoveOutputCacheItem(path)

        End Sub


    </script>

    <html>
     <head>
      
     </head>
     <body>
     
     <p>Clear Output Cache</p>

     <form id="Form1" method="post" runat="server">

      <asp:Button id="Button1" OnClick="Button1_Click" runat="server" Text="Button"></asp:Button>
        
     </form>
      
     </body>
    </html>

    The path should be the virtual absolute path to the items that are removed from the cache accroding to MSDN.


     

  • Re: Is there a way to Clear - - - - OutputCache ?

    11-28-2006, 11:16 AM
    Answer
    • Loading...
    • waynelambright
    • Joined on 05-23-2006, 11:26 PM
    • San Francisco
    • Posts 20

    That did the trick, thanks for the help.


     

    Wayne Lambright
    http://lambright.com
    415-750-1921 GMT-8 Pacific
Page 1 of 1 (7 items)
Microsoft Communities
Page view counter