Cache dependencies BUG.... ONE LAST FINAL ATTEMPT TO GET AN ANSWER
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngescalate' list.


Michael
This has been posted to twice to aspngescalate, twice to aspngfreeforall
and once to aspngcache without a satisfactory reply. I guess you guys must
all be on holidays.

I'm having some troubles with the application cache. I use the following
line of code to add an entry to the cache

Context.Cache.Add(cacheKey, fileInfo, new CacheDependency(filepath,
DateTime.Now.AddMinutes(1)), Cache.NoAbsoluteExpiration,
TimeSpan.FromMinutes(20), CacheItemPriority.NotRemovable, onRemoveFile);

First I create a file and then I cache an object "fileInfo" which contains
information about this file. If the file is deleted I'd like the entry in
the cache relating to this file removed, hence the addition of the
dependency. My problem is that frequently the entry is being removed
immediately with the reason "DependencyChanged".

I dont understand why this is as it shouldn't even be tracking changes to
the file for a minute. If I make the thread sleep for 400ms before adding
an entry to the cache, the entry is not being removed (this btw is an
unacceptable solution as it is not robust and speed in this app is
critical). I suspect the file system hasn't finished writing the file at
the time it's information is added to the cache, it seems like the start
time for tracking is being ignored. Is this a bug ?

Secondly my other gripe with the Cache class is that entries that do survive
dont seem to be staying in the cache anywhere near the 20 minutes I've set,
more like 2-4 minutes, with the reason "Underused", again I dont quite
understand this because it seems to be occuring even when testing with a
single item in the cache which is being used continuously.

Has anyone else experienced any of these problems have an explanation
and/or a workaround ?

webform1.aspx:-

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="AntiqueShop.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5";>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="WebForm1" method="post" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 323px; POSITION:
absolute; TOP: 180px" runat="server" Text="Button"></asp:Button>
<asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 320px; POSITION:
absolute; TOP: 74px" runat="server" Width="354px">Label</asp:Label>
</form>
</body>
</HTML>

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Caching;
using System.Text;
using System.IO;

namespace AntiqueShop
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected class AFileInfo
{
public string fileName;
public string path;
}

protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label1;
private CacheItemRemovedCallback onRemoveFile = null;
static int count = 0;

private void Page_Load(object sender, System.EventArgs e)
{
onRemoveFile = new CacheItemRemovedCallback(RemoveCachedFileCallback);
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
string testFile = "testit" + count.ToString() + ".txt";
string filepath = MapPath(testFile);

AFileInfo afileInfo = new AFileInfo();
afileInfo.fileName = Path.GetFileName(testFile);
afileInfo.path = filepath;

Cache.Add(count.ToString(), afileInfo, new CacheDependency(filepath,
DateTime.Now.AddMinutes(1)), Cache.NoAbsoluteExpiration,
TimeSpan.FromMinutes(20), CacheItemPriority.NotRemovable,
onRemoveFile);

FileStream testStream = File.Open(filepath, FileMode.OpenOrCreate);
byte [] testbytes UnicodeEncoding.Unicode.GetBytes(DateTime.Now.ToString());
testStream.Write(testbytes, 0, testbytes.Length);
testStream.Close();

++count;
}

private void RemoveCachedFileCallback(string k, object v,
CacheItemRemovedReason r)
{
try
{
AFileInfo afileInfo = (AFileInfo)v;
if (afileInfo != null)
File.Delete(afileInfo.path);
}
catch(Exception e)
{
Label1.Text = e.Message;
}
}
}
}

Michael Lang
MS .NET Developer
Ph: +61 4 17498620
www.michaellang.com.au
Reply to this message...
 
    
Paul D. Murphy
I'm not spending time on the cache list anymore, but you might want to
hit the news archives and peek out Rob Howards posts. I think-- this
could be bad information - that there are some heuristics in the cache
that you don't have total control over that will depending on the
environment release your objects early. I believe Rob made a post that
described this at one point in time. Again, I'm going entirely off of
memory and Robs post might have been about a completely different issue.

I'm curious about your testing environment. Are you testing the code
under the extreme load the application will demand? Or on your
workstation? The difference in the load might have an impact on the
performance if my memory is correct.

Paul

-----Original Message-----
From: Michael [mailto:Click here to reveal e-mail address]
Sent: Thursday, June 13, 2002 10:05 AM
To: aspngescalate
Subject: [aspngescalate] Cache dependencies BUG.... ONE LAST FINAL
ATTEMPT TO GET AN ANSWER

This has been posted to twice to aspngescalate, twice to aspngfreeforall

and once to aspngcache without a satisfactory reply. I guess you guys
must all be on holidays.

I'm having some troubles with the application cache. I use the
following
line of code to add an entry to the cache

Context.Cache.Add(cacheKey, fileInfo, new CacheDependency(filepath,
DateTime.Now.AddMinutes(1)), Cache.NoAbsoluteExpiration,
TimeSpan.FromMinutes(20), CacheItemPriority.NotRemovable, onRemoveFile);

First I create a file and then I cache an object "fileInfo" which
contains
information about this file. If the file is deleted I'd like the entry
in
the cache relating to this file removed, hence the addition of the
dependency. My problem is that frequently the entry is being removed
immediately with the reason "DependencyChanged".

I dont understand why this is as it shouldn't even be tracking changes
to
the file for a minute. If I make the thread sleep for 400ms before
adding
an entry to the cache, the entry is not being removed (this btw is an
unacceptable solution as it is not robust and speed in this app is
critical). I suspect the file system hasn't finished writing the file
at
the time it's information is added to the cache, it seems like the start
time for tracking is being ignored. Is this a bug ?

Secondly my other gripe with the Cache class is that entries that do
survive
dont seem to be staying in the cache anywhere near the 20 minutes I've
set,
more like 2-4 minutes, with the reason "Underused", again I dont quite
understand this because it seems to be occuring even when testing with a
single item in the cache which is being used continuously.

Has anyone else experienced any of these problems have an explanation
and/or a workaround ?

webform1.aspx:-

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false"
Inherits="AntiqueShop.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5";>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="WebForm1" method="post" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 323px; POSITION:
absolute; TOP: 180px" runat="server" Text="Button"></asp:Button>
<asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 320px; POSITION:
absolute; TOP: 74px" runat="server" Width="354px">Label</asp:Label>
</form>
</body>
</HTML>

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Caching;
using System.Text;
using System.IO;

namespace AntiqueShop
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected class AFileInfo
{
public string fileName;
public string path;
}

protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label1;
private CacheItemRemovedCallback onRemoveFile = null;
static int count = 0;

private void Page_Load(object sender, System.EventArgs e)
{
onRemoveFile = new
CacheItemRemovedCallback(RemoveCachedFileCallback);
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
string testFile = "testit" + count.ToString() + ".txt";
string filepath = MapPath(testFile);

AFileInfo afileInfo = new AFileInfo();
afileInfo.fileName = Path.GetFileName(testFile);
afileInfo.path = filepath;

Cache.Add(count.ToString(), afileInfo, new CacheDependency(filepath,
DateTime.Now.AddMinutes(1)), Cache.NoAbsoluteExpiration,
TimeSpan.FromMinutes(20), CacheItemPriority.NotRemovable,
onRemoveFile);

FileStream testStream = File.Open(filepath, FileMode.OpenOrCreate);
byte [] testbytes UnicodeEncoding.Unicode.GetBytes(DateTime.Now.ToString());
testStream.Write(testbytes, 0, testbytes.Length);
testStream.Close();

++count;
}

private void RemoveCachedFileCallback(string k, object v,
CacheItemRemovedReason r)
{
try
{
AFileInfo afileInfo = (AFileInfo)v;
if (afileInfo != null)
File.Delete(afileInfo.path);
}
catch(Exception e)
{
Label1.Text = e.Message;
}
}

}
}

Michael Lang
MS .NET Developer
Ph: +61 4 17498620
www.michaellang.com.au <http://www.michaellang.com.au/>

| [aspngescalate] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT
Reply to this message...
 
    
Michael
The code example listed below produces inconsistant results on a workstation
with a single session.

It appears that the cache dependency option to delay tracking to a certain
time simply doesn't work and that tracking begins immediately..... unless
I'm misunderstanding it (I hope I am because it would make my life at lot
easier if this did work).

-----Original Message-----
From: Paul D. Murphy [mailto:Click here to reveal e-mail address]
Sent: Friday, 14 June 2002 8:34 AM
To: aspngescalate
Subject: [aspngescalate] RE: Cache dependencies BUG.... ONE LAST FINAL
ATTEMPT TO GET AN ANSWER

I'm not spending time on the cache list anymore, but you might want to hit
the news archives and peek out Rob Howards posts. I think-- this could be
bad information - that there are some heuristics in the cache that you don't
have total control over that will depending on the environment release your
objects early. I believe Rob made a post that described this at one point in
time. Again, I'm going entirely off of memory and Robs post might have been
about a completely different issue.

I'm curious about your testing environment. Are you testing the code under
the extreme load the application will demand? Or on your workstation? The
difference in the load might have an impact on the performance if my memory
is correct.

Paul

-----Original Message-----
From: Michael [mailto:Click here to reveal e-mail address]
Sent: Thursday, June 13, 2002 10:05 AM
To: aspngescalate
Subject: [aspngescalate] Cache dependencies BUG.... ONE LAST FINAL ATTEMPT
TO GET AN ANSWER

This has been posted to twice to aspngescalate, twice to aspngfreeforall
and once to aspngcache without a satisfactory reply. I guess you guys must
all be on holidays.

I'm having some troubles with the application cache. I use the following
line of code to add an entry to the cache

Context.Cache.Add(cacheKey, fileInfo, new CacheDependency(filepath,
DateTime.Now.AddMinutes(1)), Cache.NoAbsoluteExpiration,
TimeSpan.FromMinutes(20), CacheItemPriority.NotRemovable, onRemoveFile);

First I create a file and then I cache an object "fileInfo" which contains
information about this file. If the file is deleted I'd like the entry in
the cache relating to this file removed, hence the addition of the
dependency. My problem is that frequently the entry is being removed
immediately with the reason "DependencyChanged".

I dont understand why this is as it shouldn't even be tracking changes to
the file for a minute. If I make the thread sleep for 400ms before adding
an entry to the cache, the entry is not being removed (this btw is an
unacceptable solution as it is not robust and speed in this app is
critical). I suspect the file system hasn't finished writing the file at
the time it's information is added to the cache, it seems like the start
time for tracking is being ignored. Is this a bug ?

Secondly my other gripe with the Cache class is that entries that do survive
dont seem to be staying in the cache anywhere near the 20 minutes I've set,
more like 2-4 minutes, with the reason "Underused", again I dont quite
understand this because it seems to be occuring even when testing with a
single item in the cache which is being used continuously.

Has anyone else experienced any of these problems have an explanation
and/or a workaround ?

webform1.aspx:-

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="AntiqueShop.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content=" http://schemas.microsoft.com/intellisense/ie5
<http://schemas.microsoft.com/intellisense/ie5> ">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="WebForm1" method="post" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 323px; POSITION:
absolute; TOP: 180px" runat="server" Text="Button"></asp:Button>
<asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 320px; POSITION:
absolute; TOP: 74px" runat="server" Width="354px">Label</asp:Label>
</form>
</body>
</HTML>

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Caching;
using System.Text;
using System.IO;

namespace AntiqueShop
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected class AFileInfo
{
public string fileName;
public string path;
}

protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label1;
private CacheItemRemovedCallback onRemoveFile = null;
static int count = 0;

private void Page_Load(object sender, System.EventArgs e)
{
onRemoveFile = new CacheItemRemovedCallback(RemoveCachedFileCallback);
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
string testFile = "testit" + count.ToString() + ".txt";
string filepath = MapPath(testFile);

AFileInfo afileInfo = new AFileInfo();
afileInfo.fileName = Path.GetFileName(testFile);
afileInfo.path = filepath;

Cache.Add(count.ToString(), afileInfo, new CacheDependency(filepath,
DateTime.Now.AddMinutes(1)), Cache.NoAbsoluteExpiration,
TimeSpan.FromMinutes(20), CacheItemPriority.NotRemovable,
onRemoveFile);

FileStream testStream = File.Open(filepath, FileMode.OpenOrCreate);
byte [] testbytes UnicodeEncoding.Unicode.GetBytes(DateTime.Now.ToString());
testStream.Write(testbytes, 0, testbytes.Length);
testStream.Close();

++count;
}

private void RemoveCachedFileCallback(string k, object v,
CacheItemRemovedReason r)
{
try
{
AFileInfo afileInfo = (AFileInfo)v;
if (afileInfo != null)
File.Delete(afileInfo.path);
}
catch(Exception e)
{
Label1.Text = e.Message;
}
}

}
}

Michael Lang

MS .NET Developer
Ph: +61 4 17498620
<http://www.michaellang.com.au/> www.michaellang.com.au

| [aspngescalate] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT

| [aspngescalate] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT
Reply to this message...
 
    
Michael
It's simply a means of triggering removal of a cache entry based on the date
and time stamp of the file. I think the idea behind linking cache entries
to the date time stamp on a file is to cater for a common scenario where you
fetch the data from the cache and if it is not found in the cache reload it
from a file. In my instance I'm doing things a little differently. I'm
creating a file based on a http request, rather than recreating this file
for every request that comes through. I'm linking the requests details to
the file using an entry in the cache. When a request comes in I check the
cache for the request and fetch the details of the file. If the file is
deleted I want the entry removed from the cache so it gets recreated. My
problem is the file is sometimes being deleted immediately after its added
to the cache because the cache framework thinks the file has changed. I've
attempted to use the delay to try and avoid this confusion..... with no
success.
-----Original Message-----
From: Feduke Cntr Charles R [mailto:Click here to reveal e-mail address]
Sent: Saturday, 15 June 2002 12:00 AM
To: aspngescalate
Subject: [aspngescalate] RE: Cache dependencies BUG.... ONE LAST FINAL
ATTEMPT TO GET AN ANSWER

I've been reading this cache thread and the lack of answers for it. This
got me thinking, because obviously I must be implementing the cache wrong,
why does the cache link to files on disk in the first place? I wrote a
wrapper class for my ASP.NET application that will load a dataset on request
to it if its not already loaded from the cache (reload if necessary) and
reads all the SQL Select statement from a *.xml file I wrote when requested.
What's the right way to use the cache?

— Chuck
-----Original Message-----
From: Paul D. Murphy [mailto:Click here to reveal e-mail address]
Sent: Thursday, June 13, 2002 6:34 PM
To: aspngescalate
Subject: [aspngescalate] RE: Cache dependencies BUG.... ONE LAST FINAL
ATTEMPT TO GET AN ANSWER

I’m not spending time on the cache list anymore, but you might want to
hit the news archives and peek out Rob Howards posts. I think-- this could
be bad information – that there are some heuristics in the cache that you
don’t have total control over that will depending on the environment release
your objects early. I believe Rob made a post that described this at one
point in time. Again, I’m going entirely off of memory and Robs post might
have been about a completely different issue.

I’m curious about your testing environment. Are you testing the code
under the extreme load the application will demand? Or on your workstation?
The difference in the load might have an impact on the performance if my
memory is correct.

Paul

-----Original Message-----
From: Michael [mailto:Click here to reveal e-mail address]
Sent: Thursday, June 13, 2002 10:05 AM
To: aspngescalate
Subject: [aspngescalate] Cache dependencies BUG.... ONE LAST FINAL
ATTEMPT TO GET AN ANSWER

This has been posted to twice to aspngescalate, twice to aspngfreeforall
and once to aspngcache without a satisfactory reply. I guess you guys
must all be on holidays.

I'm having some troubles with the application cache. I use the
following
line of code to add an entry to the cache

Context.Cache.Add(cacheKey, fileInfo, new CacheDependency(filepath,
DateTime.Now.AddMinutes(1)), Cache.NoAbsoluteExpiration,
TimeSpan.FromMinutes(20), CacheItemPriority.NotRemovable, onRemoveFile);

First I create a file and then I cache an object "fileInfo" which
contains
information about this file. If the file is deleted I'd like the entry
in
the cache relating to this file removed, hence the addition of the
dependency. My problem is that frequently the entry is being removed
immediately with the reason "DependencyChanged".

I dont understand why this is as it shouldn't even be tracking changes
to
the file for a minute. If I make the thread sleep for 400ms before
adding
an entry to the cache, the entry is not being removed (this btw is an
unacceptable solution as it is not robust and speed in this app is
critical). I suspect the file system hasn't finished writing the file
at
the time it's information is added to the cache, it seems like the start
time for tracking is being ignored. Is this a bug ?

Secondly my other gripe with the Cache class is that entries that do
survive
dont seem to be staying in the cache anywhere near the 20 minutes I've
set,
more like 2-4 minutes, with the reason "Underused", again I dont quite
understand this because it seems to be occuring even when testing with a
single item in the cache which is being used continuously.

Has anyone else experienced any of these problems have an explanation
and/or a workaround ?

webform1.aspx:-

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false"
Inherits="AntiqueShop.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5";>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="WebForm1" method="post" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 323px; POSITION:
absolute; TOP: 180px" runat="server" Text="Button"></asp:Button>
<asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 320px; POSITION:
absolute; TOP: 74px" runat="server" Width="354px">Label</asp:Label>
</form>
</body>
</HTML>

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Caching;
using System.Text;
using System.IO;

namespace AntiqueShop
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected class AFileInfo
{
public string fileName;
public string path;
}

protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label1;
private CacheItemRemovedCallback onRemoveFile = null;
static int count = 0;

private void Page_Load(object sender, System.EventArgs e)
{
onRemoveFile = new
CacheItemRemovedCallback(RemoveCachedFileCallback);
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
string testFile = "testit" + count.ToString() + ".txt";
string filepath = MapPath(testFile);

AFileInfo afileInfo = new AFileInfo();
afileInfo.fileName = Path.GetFileName(testFile);
afileInfo.path = filepath;

Cache.Add(count.ToString(), afileInfo, new CacheDependency(filepath,
DateTime.Now.AddMinutes(1)), Cache.NoAbsoluteExpiration,
TimeSpan.FromMinutes(20), CacheItemPriority.NotRemovable,
onRemoveFile);

FileStream testStream = File.Open(filepath, FileMode.OpenOrCreate);
byte [] testbytes UnicodeEncoding.Unicode.GetBytes(DateTime.Now.ToString());
testStream.Write(testbytes, 0, testbytes.Length);
testStream.Close();

++count;
}

private void RemoveCachedFileCallback(string k, object v,
CacheItemRemovedReason r)
{
try
{
AFileInfo afileInfo = (AFileInfo)v;
if (afileInfo != null)
File.Delete(afileInfo.path);
}
catch(Exception e)
{
Label1.Text = e.Message;
}
}

}
}

Michael Lang

MS .NET Developer
Ph: +61 4 17498620
www.michaellang.com.au

| [aspngescalate] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT

| [aspngescalate] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT
| [aspngescalate] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT
Reply to this message...
 
    
Martin Garins
SSB3b3VsZCB0aGluayByYXRoZXIgdGhhbiB1c2luZyB0aGUgYnVpbHQgaW4gY2FjaGUgbWVjaGFu
aXNtIHdoaWNoIHdhcyBub3QgcmVhbGx5IGRlc2lnbmVkIGZvciB5b3VyIHB1cnBvc2UuDQpZb3Ug
c2hvdWxkIGxvb2sgYXQgd3JpdGluZyB5b3VyIG93biBzdHJ1Y3R1cmUgYW5kIGFuZCB1c2UgdGhl
IGZpbGVzeXN0ZW0gd2F0Y2hlciBvYmplY3QgdG8gd2F0Y2ggZm9yIGNoYW5nZXMgdG8gZmlsZXMg
YW5kIHJlbW92ZSBvciBhZGQgdGhlbSB5b3UgeW91ciBvd24gY2FjaGUgYXMgbmVlZGVkLg0KIA0K
SWYgSSB3YXMgdHJ5aW5nIHRvIGRvIHdoYXQgSSB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ZS5hc3AgPSBKT0lOL1FVSVQgDQoN
CgkJCXwgW2FzcG5nZXNjYWxhdGVdIG1lbWJlciBmZWR1a2VjckBtY3NjLnVzbWMubWlsID0gWU9V
UiBJRCB8IGh0dHA6Ly93d3cuYXNwbGlzdHMuY29tL2FzcGxpc3RzL2FzcG5nZXNjYWxhdGUuYXNw
ID0gSk9JTi9RVUlUIA0KDQoJCXwgW2FzcG5nZXNjYWxhdGVdIG1lbWJlciBkYXJrbGluZ0BvemVt
YWlsLmNvbS5hdSA9IFlPVVIgSUQgfCBodHRwOi8vd3d3LmFzcGxpc3RzLmNvbS9hc3BsaXN0cy9h
c3BuZ2VzY2FsYXRlLmFzcCA9IEpPSU4vUVVJVCANCg0KCXwgW2FzcG5nZXNjYWxhdGVdIG1lbWJl
ciBtZ2FyaW5zQGUtaW50ZXJzZWN0LmNvbSA9IFlPVVIgSUQgfCBodHRwOi8vd3d3LmFzcGxpc3Rz
LmNvbS9hc3BsaXN0cy9hc3BuZ2VzY2FsYXRlLmFzcCA9IEpPSU4vUVVJVCA8IC9CTE9DS1FVT1RF
ID4gDQoNCg=
Reply to this message...
 
    
Michael
I've not used the FileSystemWatcher class before but it appears that it's
not going to help me as it's docs suggest it's intended to be used to
monitor directories where as I would need it to observe individual files.

I already have a simple work around for this and that is to fetch it's
details from the cache the do a System.IO.File.Exists and recreate the file
if it has been deleted. This however is extremely ineffecient as I'm now
doing extra disk access on every request, which from my measurements is
causing up to a 30% degradation in performance, from the solution which uses
the cache's file dependencies functionality (which is only working
sometimes).... I'm far from happy with this solution.

I'm surprised that writting my own cache api is the most sensible solution
here. I think the ASP.NET Cache api is a close match to what I need
(especially if it functioned as expected).

I basically want the processing for a request to be cached for a period of
time and in the normal course the Cache itself to decide when a file is
deleted, however I would like the to be able to force a refresh by manually
removing files, hence the attempted use of dependencies. The only
difference between my requirements and those of the more common scenario is
that I wish to store only the details of my data and not the data itself in
the cache.... this is mainly because of the size of the data and the number
of requests which makes storing it directly in the cache too much of a
burden on system memory.

I still haven't actually had anyone say that they too can repeat the
behaviour I've described and that they believe it is a bug. If I'm
misunderstanding something here I would definitely like to know what it is.

-----Original Message-----
From: Martin Garins [mailto:Click here to reveal e-mail address]
Sent: Sunday, 16 June 2002 5:56 AM
To: aspngescalate
Subject: RE: [aspngescalate] RE: Cache dependencies BUG.... ONE LAST FINAL
ATTEMPT TO GET AN ANSWER

I would think rather than using the built in cache mechanism which was not
really designed for your purpose.
You should look at writing your own structure and and use the filesystem
watcher object to watch for changes to files and remove or add them you your
own cache as needed.

If I was trying to do what I think you are trying to do this is how I would
do it.

Marty

-----Original Message-----
From: Michael [mailto:Click here to reveal e-mail address]
Sent: Sat 6/15/2002 10:37 AM
To: aspngescalate
Cc:
Subject: [aspngescalate] RE: Cache dependencies BUG.... ONE LAST FINAL
ATTEMPT TO GET AN ANSWER

It's simply a means of triggering removal of a cache entry based on the date
and time stamp of the file. I think the idea behind linking cache entries
to the date time stamp on a file is to cater for a common scenario where you
fetch the data from the cache and if it is not found in the cache reload it
from a file. In my instance I'm doing things a little differently. I'm
creating a file based on a http request, rather than recreating this file
for every request that comes through. I'm linking the requests details to
the file using an entry in the cache. When a request comes in I check the
cache for the request and fetch the details of the file. If the file is
deleted I want the entry removed from the cache so it gets recreated. My
problem is the file is sometimes being deleted immediately after its added
to the cache because the cache framework thinks the file has changed. I've
attempted to use the delay to try and avoid this confusion..... with no
success.

-----Original Message-----
From: Feduke Cntr Charles R [mailto:Click here to reveal e-mail address]
Sent: Saturday, 15 June 2002 12:00 AM
To: aspngescalate
Subject: [aspngescalate] RE: Cache dependencies BUG.... ONE LAST FINAL
ATTEMPT TO GET AN ANSWER

I've been reading this cache thread and the lack of answers for it. This
got me thinking, because obviously I must be implementing the cache wrong,
why does the cache link to files on disk in the first place? I wrote a
wrapper class for my ASP.NET application that will load a dataset on request
to it if its not already loaded from the cache (reload if necessary) and
reads all the SQL Select statement from a *.xml file I wrote when requested.
What's the right way to use the cache?

- Chuck

-----Original Message-----
From: Paul D. Murphy [mailto:Click here to reveal e-mail address]
Sent: Thursday, June 13, 2002 6:34 PM
To: aspngescalate
Subject: [aspngescalate] RE: Cache dependencies BUG.... ONE LAST FINAL
ATTEMPT TO GET AN ANSWER

I'm not spending time on the cache list anymore, but you might want to hit
the news archives and peek out Rob Howards posts. I think-- this could be
bad information - that there are some heuristics in the cache that you don't
have total control over that will depending on the environment release your
objects early. I believe Rob made a post that described this at one point in
time. Again, I'm going entirely off of memory and Robs post might have been
about a completely different issue.

I'm curious about your testing environment. Are you testing the code under
the extreme load the application will demand? Or on your workstation? The
difference in the load might have an impact on the performance if my memory
is correct.

Paul

-----Original Message-----
From: Michael [mailto:Click here to reveal e-mail address]
Sent: Thursday, June 13, 2002 10:05 AM
To: aspngescalate
Subject: [aspngescalate] Cache dependencies BUG.... ONE LAST FINAL ATTEMPT
TO GET AN ANSWER

This has been posted to twice to aspngescalate, twice to aspngfreeforall
and once to aspngcache without a satisfactory reply. I guess you guys must
all be on holidays.

I'm having some troubles with the application cache. I use the following
line of code to add an entry to the cache

Context.Cache.Add(cacheKey, fileInfo, new CacheDependency(filepath,
DateTime.Now.AddMinutes(1)), Cache.NoAbsoluteExpiration,
TimeSpan.FromMinutes(20), CacheItemPriority.NotRemovable, onRemoveFile);

First I create a file and then I cache an object "fileInfo" which contains
information about this file. If the file is deleted I'd like the entry in
the cache relating to this file removed, hence the addition of the
dependency. My problem is that frequently the entry is being removed
immediately with the reason "DependencyChanged".

I dont understand why this is as it shouldn't even be tracking changes to
the file for a minute. If I make the thread sleep for 400ms before adding
an entry to the cache, the entry is not being removed (this btw is an
unacceptable solution as it is not robust and speed in this app is
critical). I suspect the file system hasn't finished writing the file at
the time it's information is added to the cache, it seems like the start
time for tracking is being ignored. Is this a bug ?

Secondly my other gripe with the Cache class is that entries that do survive
dont seem to be staying in the cache anywhere near the 20 minutes I've set,
more like 2-4 minutes, with the reason "Underused", again I dont quite
understand this because it seems to be occuring even when testing with a
single item in the cache which is being used continuously.

Has anyone else experienced any of these problems have an explanation
and/or a workaround ?

webform1.aspx:-

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="AntiqueShop.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content=" http://schemas.microsoft.com/intellisense/ie5
<http://schemas.microsoft.com/intellisense/ie5> ">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="WebForm1" method="post" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 323px; POSITION:
absolute; TOP: 180px" runat="server" Text="Button"></asp:Button>
<asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 320px; POSITION:
absolute; TOP: 74px" runat="server" Width="354px">Label</asp:Label>
</form>
</body>
</HTML>

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Caching;
using System.Text;
using System.IO;

namespace AntiqueShop
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected class AFileInfo
{
public string fileName;
public string path;
}

protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label1;
private CacheItemRemovedCallback onRemoveFile = null;
static int count = 0;

private void Page_Load(object sender, System.EventArgs e)
{
onRemoveFile = new CacheItemRemovedCallback(RemoveCachedFileCallback);
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
string testFile = "testit" + count.ToString() + ".txt";
string filepath = MapPath(testFile);

AFileInfo afileInfo = new AFileInfo();
afileInfo.fileName = Path.GetFileName(testFile);
afileInfo.path = filepath;

Cache.Add(count.ToString(), afileInfo, new CacheDependency(filepath,
DateTime.Now.AddMinutes(1)), Cache.NoAbsoluteExpiration,
TimeSpan.FromMinutes(20), CacheItemPriority.NotRemovable,
onRemoveFile);

FileStream testStream = File.Open(filepath, FileMode.OpenOrCreate);
byte [] testbytes UnicodeEncoding.Unicode.GetBytes(DateTime.Now.ToString());
testStream.Write(testbytes, 0, testbytes.Length);
testStream.Close();

++count;
}

private void RemoveCachedFileCallback(string k, object v,
CacheItemRemovedReason r)
{
try
{
AFileInfo afileInfo = (AFileInfo)v;
if (afileInfo != null)
File.Delete(afileInfo.path);
}
catch(Exception e)
{
Label1.Text = e.Message;
}
}

}
}

Michael Lang

MS .NET Developer
Ph: +61 4 17498620
www.michaellang.com.au <http://www.michaellang.com.au/>

| [aspngescalate] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT

| [aspngescalate] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT

| [aspngescalate] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT

| [aspngescalate] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT < /BLOCKQUOTE
>
Reply to this message...
 
    
Martin Garins
The FileSystemWatcher can wathc Files and/or directories
Here are the events

Public Events

public event<ms-help://MS.VSCC/MS.MSDNVS/cpref/html/pubevent.gif>
Changed
<ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemiofilesystemwatchercl
asschangedtopic.htm>      Occurs when a file or directory in the
specified Path
<ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemiofilesystemwatchercl
asspathtopic.htm> is changed.
public event<ms-help://MS.VSCC/MS.MSDNVS/cpref/html/pubevent.gif>
Created
<ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemiofilesystemwatchercl
asscreatedtopic.htm>      Occurs when a file or directory in the
specified Path
<ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemiofilesystemwatchercl
asspathtopic.htm> is created.
public event<ms-help://MS.VSCC/MS.MSDNVS/cpref/html/pubevent.gif>
Deleted
<ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemiofilesystemwatchercl
assdeletedtopic.htm>      Occurs when a file or directory in the
specified Path
<ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemiofilesystemwatchercl
asspathtopic.htm> is deleted.
public event<ms-help://MS.VSCC/MS.MSDNVS/cpref/html/pubevent.gif>
Disposed
<ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemcomponentmodelcompone
ntclassdisposedtopic.htm> (inherited from Component)     Adds an event
handler to listen to the Disposed
<ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemcomponentmodelcompone
ntclassdisposedtopic.htm> event on the component.
public event<ms-help://MS.VSCC/MS.MSDNVS/cpref/html/pubevent.gif> Error
<ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemiofilesystemwatchercl
asserrortopic.htm>      Occurs when the internal buffer overflows.
public event<ms-help://MS.VSCC/MS.MSDNVS/cpref/html/pubevent.gif>
Renamed
<ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemiofilesystemwatchercl
assrenamedtopic.htm>      Occurs when a file or directory in the
specified Path
<ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemiofilesystemwatchercl
asspathtopic.htm> is renamed.

This came directly from the documentaions here
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemiofilesystemwatchermem
berstopic.htm

Martin Garins, MCSD
Vice President - Technology
e-Intersect Corp.
http://www.e-intersect.com <http://www.e-intersect.com/>
http://www.jppex.com <http://www.jppex.com/" target="_blank">http://www.jppex.com/>

    -----Original Message-----
    From: Michael [mailto:Click here to reveal e-mail address]
    Sent: Sunday, June 16, 2002 8:30 PM
    To: aspngescalate
    Subject: [aspngescalate] RE: Cache dependencies BUG.... ONE LAST
FINAL ATTEMPT TO GET AN ANSWER


    I've not used the FileSystemWatcher class before but it appears
that it's not going to help me as it's docs suggest it's intended to be
used to monitor directories where as I would need it to observe
individual files.
    
    I already have a simple work around for this and that is to
fetch it's details from the cache the do a System.IO.File.Exists and
recreate the file if it has been deleted. This however is extremely
ineffecient as I'm now doing extra disk access on every request, which
from my measurements is causing up to a 30% degradation in performance,
from the solution which uses the cache's file dependencies functionality
(which is only working sometimes).... I'm far from happy with this
solution.
    
    I'm surprised that writting my own cache api is the most
sensible solution here. I think the ASP.NET Cache api is a close match
to what I need (especially if it functioned as expected).
    
    I basically want the processing for a request to be cached for a
period of time and in the normal course the Cache itself to decide when
a file is deleted, however I would like the to be able to force a
refresh by manually removing files, hence the attempted use of
dependencies. The only difference between my requirements and those of
the more common scenario is that I wish to store only the details of my
data and not the data itself in the cache.... this is mainly because of
the size of the data and the number of requests which makes storing it
directly in the cache too much of a burden on system memory.
    
    I still haven't actually had anyone say that they too can repeat
the behaviour I've described and that they believe it is a bug. If I'm
misunderstanding something here I would definitely like to know what it
is.
    

    -----Original Message-----
    From: Martin Garins [mailto:Click here to reveal e-mail address]
    Sent: Sunday, 16 June 2002 5:56 AM
    To: aspngescalate
    Subject: RE: [aspngescalate] RE: Cache dependencies BUG.... ONE
LAST FINAL ATTEMPT TO GET AN ANSWER



        I would think rather than using the built in cache
mechanism which was not really designed for your purpose.
        You should look at writing your own structure and and
use the filesystem watcher object to watch for changes to files and
remove or add them you your own cache as needed.
        
        If I was trying to do what I think you are trying to do
this is how I would do it.
        
        Marty

            -----Original Message-----
            From: Michael [mailto:Click here to reveal e-mail address]
            Sent: Sat 6/15/2002 10:37 AM
            To: aspngescalate
            Cc:
            Subject: [aspngescalate] RE: Cache dependencies
BUG.... ONE LAST FINAL ATTEMPT TO GET AN ANSWER
        
        
            It's simply a means of triggering removal of a
cache entry based on the date and time stamp of the file. I think the
idea behind linking cache entries to the date time stamp on a file is to
cater for a common scenario where you fetch the data from the cache and
if it is not found in the cache reload it from a file. In my instance
I'm doing things a little differently. I'm creating a file based on a
http request, rather than recreating this file for every request that
comes through. I'm linking the requests details to the file using an
entry in the cache. When a request comes in I check the cache for the
request and fetch the details of the file. If the file is deleted I
want the entry removed from the cache so it gets recreated. My problem
is the file is sometimes being deleted immediately after its added to
the cache because the cache framework thinks the file has changed. I've
attempted to use the delay to try and avoid this confusion..... with no
success.

                -----Original Message-----
                From: Feduke Cntr Charles R
[mailto:Click here to reveal e-mail address]
                Sent: Saturday, 15 June 2002 12:00 AM
                To: aspngescalate
                Subject: [aspngescalate] RE: Cache
dependencies BUG.... ONE LAST FINAL ATTEMPT TO GET AN ANSWER
            
            
                I've been reading this cache thread and
the lack of answers for it. This got me thinking, because obviously I
must be implementing the cache wrong, why does the cache link to files
on disk in the first place? I wrote a wrapper class for my ASP.NET
application that will load a dataset on request to it if its not already
loaded from the cache (reload if necessary) and reads all the SQL Select
statement from a *.xml file I wrote when requested. What's the right
way to use the cache?
                
                - Chuck

                -----Original Message-----
                From: Paul D. Murphy
[mailto:Click here to reveal e-mail address]
                Sent: Thursday, June 13, 2002 6:34 PM
                To: aspngescalate
                Subject: [aspngescalate] RE: Cache
dependencies BUG.... ONE LAST FINAL ATTEMPT TO GET AN ANSWER
            
            

                I'm not spending time on the cache list
anymore, but you might want to hit the news archives and peek out Rob
Howards posts. I think-- this could be bad information - that there are
some heuristics in the cache that you don't have total control over that
will depending on the environment release your objects early. I believe
Rob made a post that described this at one point in time. Again, I'm
going entirely off of memory and Robs post might have been about a
completely different issue.

                

                I'm curious about your testing
environment. Are you testing the code under the extreme load the
application will demand? Or on your workstation? The difference in the
load might have an impact on the performance if my memory is correct.

                

                

                Paul

                

                

                

                -----Original Message-----
                From: Michael
[mailto:Click here to reveal e-mail address]
                Sent: Thursday, June 13, 2002 10:05 AM
                To: aspngescalate
                Subject: [aspngescalate] Cache
dependencies BUG.... ONE LAST FINAL ATTEMPT TO GET AN ANSWER

                

                This has been posted to twice to
aspngescalate, twice to aspngfreeforall
                and once to aspngcache without a
satisfactory reply. I guess you guys must all be on holidays.

                

                I'm having some troubles with the
application cache. I use the following
                line of code to add an entry to the
cache

                

                Context.Cache.Add(cacheKey, fileInfo,
new CacheDependency(filepath,
                DateTime.Now.AddMinutes(1)),
Cache.NoAbsoluteExpiration,
                TimeSpan.FromMinutes(20),
CacheItemPriority.NotRemovable, onRemoveFile);

                

                First I create a file and then I cache
an object "fileInfo" which contains
                information about this file. If the
file is deleted I'd like the entry in
                the cache relating to this file removed,
hence the addition of the
                dependency. My problem is that
frequently the entry is being removed
                immediately with the reason
"DependencyChanged".

                

                I dont understand why this is as it
shouldn't even be tracking changes to
                the file for a minute. If I make the
thread sleep for 400ms before adding
                an entry to the cache, the entry is not
being removed (this btw is an
                unacceptable solution as it is not
robust and speed in this app is
                critical). I suspect the file system
hasn't finished writing the file at
                the time it's information is added to
the cache, it seems like the start
                time for tracking is being ignored. Is
this a bug ?

                

                Secondly my other gripe with the Cache
class is that entries that do survive
                dont seem to be staying in the cache
anywhere near the 20 minutes I've set,
                more like 2-4 minutes, with the reason
"Underused", again I dont quite
                understand this because it seems to be
occuring even when testing with a
                single item in the cache which is being
used continuously.

                

                Has anyone else experienced any of these
problems have an explanation
                and/or a workaround ?

                webform1.aspx:-

                

                <%@ Page language="c#"
Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
                Inherits="AntiqueShop.WebForm1" %>
                <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.0 Transitional//EN" >
                <HTML>
                 <HEAD>
                 <title>WebForm1</title>
                 <meta name="GENERATOR"
Content="Microsoft Visual Studio 7.0">
                 <meta name="CODE_LANGUAGE"
Content="C#">
                 <meta name="vs_defaultClientScript"
content="JavaScript">
                 <meta name="vs_targetSchema"

content="http://schemas.microsoft.com/intellisense/ie5";>
                 </HEAD>
                 <body MS_POSITIONING="GridLayout">
                 <form id="WebForm1" method="post"
runat="server">
                 <asp:Button id="Button1"
style="Z-INDEX: 101; LEFT: 323px; POSITION:
                absolute; TOP: 180px" runat="server"
Text="Button"></asp:Button>
                 <asp:Label id="Label1"
style="Z-INDEX: 102; LEFT: 320px; POSITION:
                absolute; TOP: 74px" runat="server"
Width="354px">Label</asp:Label>
                 </form>
                 </body>
                </HTML>

                

                using System;
                using System.Web;
                using System.Web.UI;
                using System.Web.UI.WebControls;
                using System.Web.Caching;
                using System.Text;
                using System.IO;

                

                namespace AntiqueShop
                {
                 /// <summary>
                 /// Summary description for WebForm1.
                 /// </summary>
                 public class WebForm1 :
System.Web.UI.Page
                 {
                 protected class AFileInfo
                 {
                 public string fileName;
                 public string path;
                 }

                

                 protected
System.Web.UI.WebControls.Button Button1;
                 protected
System.Web.UI.WebControls.Label Label1;
                 private CacheItemRemovedCallback
onRemoveFile = null;
                 static int count = 0;

                

                 private void Page_Load(object sender,
System.EventArgs e)
                 {
                 onRemoveFile = new
CacheItemRemovedCallback(RemoveCachedFileCallback);
                 }

                

                 #region Web Form Designer generated
code
                 override protected void
OnInit(EventArgs e)
                 {
                 //
                 // CODEGEN: This call is required by
the ASP.NET Web Form Designer.
                 //
                 InitializeComponent();
                 base.OnInit(e);
                 }

                

                 /// <summary>
                 /// Required method for Designer
support - do not modify
                 /// the contents of this method with
the code editor.
                 /// </summary>
                 private void InitializeComponent()
                 {
                 this.Button1.Click += new
System.EventHandler(this.Button1_Click);
                 this.Load += new
System.EventHandler(this.Page_Load);

                

                 }
                 #endregion

                

                 private void Button1_Click(object
sender, System.EventArgs e)
                 {
                 string testFile = "testit" +
count.ToString() + ".txt";
                 string filepath = MapPath(testFile);

                

                 AFileInfo afileInfo = new
AFileInfo();
                 afileInfo.fileName Path.GetFileName(testFile);
                 afileInfo.path = filepath;

                

                 Cache.Add(count.ToString(),
afileInfo, new CacheDependency(filepath,
                 DateTime.Now.AddMinutes(1)),
Cache.NoAbsoluteExpiration,
                 TimeSpan.FromMinutes(20),
CacheItemPriority.NotRemovable,
                onRemoveFile);

                

                 FileStream testStream File.Open(filepath, FileMode.OpenOrCreate);
                 byte [] testbytes
UnicodeEncoding.Unicode.GetBytes(DateTime.Now.ToString());
                 testStream.Write(testbytes, 0,
testbytes.Length);
                 testStream.Close();

                

                 ++count;
                 }

                

                 private void
RemoveCachedFileCallback(string k, object v,
                CacheItemRemovedReason r)
                 {
                 try
                 {
                 AFileInfo afileInfo = (AFileInfo)v;
                 if (afileInfo != null)
                 File.Delete(afileInfo.path);
                 }
                 catch(Exception e)
                 {
                 Label1.Text = e.Message;
                 }
                 }

                 }
                }

                Michael Lang
            

                MS .NET Developer
                Ph: +61 4 17498620
                www.michaellang.com.au
<http://www.michaellang.com.au/>

            

                

                | [aspngescalate] member
Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT

                | [aspngescalate] member
Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT

                | [aspngescalate] member
Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT

            | [aspngescalate] member Click here to reveal e-mail address
= YOUR ID | http://www.asplists.com/asplists/aspngescalate.asp JOIN/QUIT < /BLOCKQUOTE >
Reply to this message...
 
    
Paul D. Murphy
I really want to see you solve this issue and I think the best thing to
do is get a firm understanding of what you are trying to do. I
understand what the problem is with the cache, but I don't understand
what you are trying to accomplish. That would help me greatly,
understanding the goal of this process you are having trouble with.

Paul
Reply to this message...
 
    
Michael
I think caching it in RAM can be fine, as long as the amount of data is
known. I'm caching to disk as the amount of data I need to cache is
indeterminate and the process to create the data each time is costly. I've
seen one other use for using dependencies even in the instance that the
you're storing datasets directly in the cache and that is to get the cache
to refetch the data from the database when it has been updated. This is
accomplished by creating a trigger and updating a file in that trigger when
the data in a table is changed, you then use a cache dependency to observe
this file which will cause the entry in the cache to be removed when the
table is updated..... pretty cool. You can find the full details of it
here.

http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=385

-----Original Message-----
From: Feduke Cntr Charles R [mailto:Click here to reveal e-mail address]
Sent: Monday, 17 June 2002 9:27 PM
To: aspngescalate
Subject: [aspngescalate] RE: Cache dependencies BUG.... ONE LAST FINAL
ATTEMPT TO GET AN ANSWER

Ah, I think I understand now. This is why in these books I've read they
always go into detail on storing the results of recordsets in XML files on
disk and retrieving them from there. I think that my system is small enough
that its realistic that I keep all of my lookup tables in the cache in RAM
rather than in XML files on disk. However I've [obviously] never used the
cache as it was intended so I can't offer any insite to your problem.

- Chuck
-----Original Message-----
From: Michael [mailto:Click here to reveal e-mail address]
Sent: Saturday, June 15, 2002 11:37 AM
To: aspngescalate
Subject: [aspngescalate] RE: Cache dependencies BUG.... ONE LAST FINAL
ATTEMPT TO GET AN ANSWER

It's simply a means of triggering removal of a cache entry based on the
date and time stamp of the file. I think the idea behind linking cache
entries to the date time stamp on a file is to cater for a common scenario
where you fetch the data from the cache and if it is not found in the cache
reload it from a file. In my instance I'm doing things a little
differently. I'm creating a file based on a http request, rather than
recreating this file for every request that comes through. I'm linking the
requests details to the file using an entry in the cache. When a request
comes in I check the cache for the request and fetch the details of the
file. If the file is deleted I want the entry removed from the cache so it
gets recreated. My problem is the file is sometimes being deleted
immediately after its added to the cache because the cache framework thinks
the file has changed. I've attempted to use the delay to try and avoid this
confusion..... with no success.
-----Original Message-----
From: Feduke Cntr Charles R [mailto:Click here to reveal e-mail address]
Sent: Saturday, 15 June 2002 12:00 AM
To: aspngescalate
Subject: [aspngescalate] RE: Cache dependencies BUG.... ONE LAST FINAL
ATTEMPT TO GET AN ANSWER

I've been reading this cache thread and the lack of answers for it.
This got me thinking, because obviously I must be implementing the cache
wrong, why does the cache link to files on disk in the first place? I wrote
a wrapper class for my ASP.NET application that will load a dataset on
request to it if its not already loaded from the cache (reload if necessary)
and reads all the SQL Select statement from a *.xml file I wrote when
requested. What's the right way to use the cache?

- Chuck
-----Original Message-----
From: Paul D. Murphy [mailto:Click here to reveal e-mail address]
Sent: Thursday, June 13, 2002 6:34 PM
To: aspngescalate
Subject: [aspngescalate] RE: Cache dependencies BUG.... ONE LAST
FINAL ATTEMPT TO GET AN ANSWER

I'm not spending time on the cache list anymore, but you might want
to hit the news archives and peek out Rob Howards posts. I think-- this
could be bad information - that there are some heuristics in the cache that
you don't have total control over that will depending on the environment
release your objects early. I believe Rob made a post that described this at
one point in time. Again, I'm going entirely off of memory and Robs post
might have been about a completely different issue.

I'm curious about your testing environment. Are you testing the code
under the extreme load the application will demand? Or on your workstation?
The difference in the load might have an impact on the performance if my
memory is correct.

Paul

-----Original Message-----
From: Michael [mailto:Click here to reveal e-mail address]
Sent: Thursday, June 13, 2002 10:05 AM
To: aspngescalate
Subject: [aspngescalate] Cache dependencies BUG.... ONE LAST FINAL
ATTEMPT TO GET AN ANSWER

This has been posted to twice to aspngescalate, twice to
aspngfreeforall
and once to aspngcache without a satisfactory reply. I guess you
guys must all be on holidays.

I'm having some troubles with the application cache. I use the
following
line of code to add an entry to the cache

Context.Cache.Add(cacheKey, fileInfo, new CacheDependency(filepath,
DateTime.Now.AddMinutes(1)), Cache.NoAbsoluteExpiration,
TimeSpan.FromMinutes(20), CacheItemPriority.NotRemovable,
onRemoveFile);

First I create a file and then I cache an object "fileInfo" which
contains
information about this file. If the file is deleted I'd like the
entry in
the cache relating to this file removed, hence the addition of the
dependency. My problem is that frequently the entry is being
removed
immediately with the reason "DependencyChanged".

I dont understand why this is as it shouldn't even be tracking
changes to
the file for a minute. If I make the thread sleep for 400ms before
adding
an entry to the cache, the entry is not being removed (this btw is
an
unacceptable solution as it is not robust and speed in this app is
critical). I suspect the file system hasn't finished writing the
file at
the time it's information is added to the cache, it seems like the
start
time for tracking is being ignored. Is this a bug ?

Secondly my other gripe with the Cache class is that entries that do
survive
dont seem to be staying in the cache anywhere near the 20 minutes
I've set,
more like 2-4 minutes, with the reason "Underused", again I dont
quite
understand this because it seems to be occuring even when testing
with a
single item in the cache which is being used continuously.

Has anyone else experienced any of these problems have an
explanation
and/or a workaround ?

webform1.aspx:-

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false"
Inherits="AntiqueShop.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5";>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="WebForm1" method="post" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 323px;
POSITION:
absolute; TOP: 180px" runat="server" Text="Button"></asp:Button>
<asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 320px;
POSITION:
absolute; TOP: 74px" runat="server" Width="354px">Label</asp:Label>
</form>
</body>
</HTML>

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Caching;
using System.Text;
using System.IO;