Search:
Namespaces
Discussions
.NET v1.1
Feedback
Cache, expirations and dependencies - NOT ANSWERED AGAIN
Messages
Related Types
This message was discovered on
ASPFriends.com 'aspngescalate' list
.
Michael
OK no replies here either....
Here's some code to repeat the problem. To repeat the problem you'll notice
that I actually write the file after it's details are written to the cache,
in my actual system the file is being written before it's details are
written to the cache. Unless I'm misunderstanding the documentation even
though I write the file after it's been added to the cache because my
dependency specifies a time to start tracking a minute from the time it's
added to the cache the file shouldn't be getting deleted immediately with
this code either.
When I run this code and click the button a dozen times or so the result I
expect is to see the files named "testit##.text" where ##=0 to 12 what I
find is that some of the files have been deleted. If someone can at least
confirm they too get this result that would be great.
This looks like a bug to me, if someone out in Microsoft land could confirm
this and perhaps indicate there might be a fix or a workaround that'd be
great.
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;
}
}
}
}
-----Original Message-----
From: Michael [mailto:
Click here to reveal e-mail address
]
Sent: Saturday, 8 June 2002 12:33 PM
To: aspngescalate
Subject: [aspngescalate]
Cache
, expirations and dependencies - NOT
ANSWERED
This has been posted to twice to aspngfreeforall and once to aspngcache
without a reply.
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 ?
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
Reply to this message...
Michael
Thanks Trevor....
I doubt it too....
I actually forgot to post an aspx page to consume the code behind file...
Here it is....
<%@
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>
I at least know now that my posts are actually being received by someone.
-----Original Message-----
From: Trevor Pinkney [mailto:
Click here to reveal e-mail address
]
Sent: Tuesday, 11 June 2002 11:43 AM
To: aspngescalate
Subject: [aspngescalate] Re:
Cache
, expirations and dependencies - NOT
ANSWERED AGAIN
Hey Michael,
I have seen examples where people use System.
DateTime
.MaxValue instead of
Cache
.NoAbsoluteExpiration. I doubt that's it but...
-Trev
At 08:56 PM 6/10/2002 +1000, you wrote:
[Original message clipped]
| [aspngescalate] member
Click here to reveal e-mail address
= YOUR ID
|
http://www.asplists.com/asplists/aspngescalate.asp
= JOIN/QUIT
Reply to this message...
System.DateTime
System.EventArgs
System.EventHandler
System.IO.File
System.IO.FileMode
System.IO.FileStream
System.IO.Path
System.Runtime.Remoting.Contexts.Context
System.Text.UnicodeEncoding
System.TimeSpan
System.Web.Caching.Cache
System.Web.Caching.CacheDependency
System.Web.Caching.CacheItemPriority
System.Web.Caching.CacheItemRemovedCallback
System.Web.Caching.CacheItemRemovedReason
System.Web.UI.Page
System.Web.UI.WebControls.Button
System.Web.UI.WebControls.Label
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com