473,725 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cache - Removing All Items

I want to create a STATIC method that removes all items from the Cache.

Questions:
1. Is a safe thing to do (any threading issues?)

2. Is the following code a good way to get the job done - given that there
is apparently no method like Cache.Clear() or Cache.Items.Cle ar()? Or am I
missing an easier way to do it?

string currentKey= "";
System.Collecti ons.IDictionary Enumerator cacheContents =
System.Web.Http Context.Current .Cache.GetEnume rator();
while (cacheContents. MoveNext()) {
currentKey = cacheContents.K ey.ToString();
System.Web.Http Context.Current .Cache.Remove(c urrentKey);
}

Thanks!

-GH
Nov 18 '05 #1
4 4176
a better approach is to use a dependancy key in the cache, and change.

-- bruce (sqlwork.com)

"Guadala Harry" <GM**@NoSpam.co m> wrote in message
news:OW******** ******@TK2MSFTN GP10.phx.gbl...
| I want to create a STATIC method that removes all items from the Cache.
|
| Questions:
| 1. Is a safe thing to do (any threading issues?)
|
| 2. Is the following code a good way to get the job done - given that there
| is apparently no method like Cache.Clear() or Cache.Items.Cle ar()? Or am I
| missing an easier way to do it?
|
| string currentKey= "";
| System.Collecti ons.IDictionary Enumerator cacheContents =
| System.Web.Http Context.Current .Cache.GetEnume rator();
| while (cacheContents. MoveNext()) {
| currentKey = cacheContents.K ey.ToString();
| System.Web.Http Context.Current .Cache.Remove(c urrentKey);
| }
|
| Thanks!
|
| -GH
|
|
Nov 18 '05 #2
I would not do that.
There are other things that use the cache too.
You aren't the only thing adding stuff to the cache.
You could seriously break stuff.

Use cache dependencies or expirations instead soyou can control the things
that you created and added to the cache.
--
Joe Fallon

"Guadala Harry" <GM**@NoSpam.co m> wrote in message
news:OW******** ******@TK2MSFTN GP10.phx.gbl...
I want to create a STATIC method that removes all items from the Cache.

Questions:
1. Is a safe thing to do (any threading issues?)

2. Is the following code a good way to get the job done - given that there
is apparently no method like Cache.Clear() or Cache.Items.Cle ar()? Or am I
missing an easier way to do it?

string currentKey= "";
System.Collecti ons.IDictionary Enumerator cacheContents =
System.Web.Http Context.Current .Cache.GetEnume rator();
while (cacheContents. MoveNext()) {
currentKey = cacheContents.K ey.ToString();
System.Web.Http Context.Current .Cache.Remove(c urrentKey);
}

Thanks!

-GH

Nov 18 '05 #3
<<You aren't the only thing adding stuff to the cache>>

That's a big one... didn't know that. Thank you.
Too bad I can't have a dependency on database tables. I already put things
in the Cache with a sliding expiration - but anything still in the Cache
reflecting the current state of the underlying database must get removed
from the Cache whenever the database gets updated. Short of waiting until
ASP.NET/2, is there any elegant way to create a dependency between Cached
data and SQL Server db tables? The only time I explicitly blow things out of
the Cache is when the db gets updated.

-GH
"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message
news:OC******** ******@TK2MSFTN GP14.phx.gbl...
I would not do that.
There are other things that use the cache too.
You aren't the only thing adding stuff to the cache.
You could seriously break stuff.

Use cache dependencies or expirations instead soyou can control the things
that you created and added to the cache.
--
Joe Fallon

"Guadala Harry" <GM**@NoSpam.co m> wrote in message
news:OW******** ******@TK2MSFTN GP10.phx.gbl...
I want to create a STATIC method that removes all items from the Cache.

Questions:
1. Is a safe thing to do (any threading issues?)

2. Is the following code a good way to get the job done - given that there is apparently no method like Cache.Clear() or Cache.Items.Cle ar()? Or am I missing an easier way to do it?

string currentKey= "";
System.Collecti ons.IDictionary Enumerator cacheContents =
System.Web.Http Context.Current .Cache.GetEnume rator();
while (cacheContents. MoveNext()) {
currentKey = cacheContents.K ey.ToString();
System.Web.Http Context.Current .Cache.Remove(c urrentKey);
}

Thanks!

-GH


Nov 18 '05 #4
Yes. I implemented DB Cache Dependency in ASP.Net 1.1.
There is a great article that describes how to do it here:
http://www.eggheadcafe.com/articles/20040607.asp
(See my comments at the bottom of this article for improvements in the
published technique.
--
Joe Fallon

"Guadala Harry" <GM**@NoSpam.co m> wrote in message
news:uq******** ******@tk2msftn gp13.phx.gbl...
<<You aren't the only thing adding stuff to the cache>>

That's a big one... didn't know that. Thank you.
Too bad I can't have a dependency on database tables. I already put things
in the Cache with a sliding expiration - but anything still in the Cache
reflecting the current state of the underlying database must get removed
from the Cache whenever the database gets updated. Short of waiting until
ASP.NET/2, is there any elegant way to create a dependency between Cached
data and SQL Server db tables? The only time I explicitly blow things out
of
the Cache is when the db gets updated.

-GH
"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message
news:OC******** ******@TK2MSFTN GP14.phx.gbl...
I would not do that.
There are other things that use the cache too.
You aren't the only thing adding stuff to the cache.
You could seriously break stuff.

Use cache dependencies or expirations instead soyou can control the
things
that you created and added to the cache.
--
Joe Fallon

"Guadala Harry" <GM**@NoSpam.co m> wrote in message
news:OW******** ******@TK2MSFTN GP10.phx.gbl...
>I want to create a STATIC method that removes all items from the Cache.
>
> Questions:
> 1. Is a safe thing to do (any threading issues?)
>
> 2. Is the following code a good way to get the job done - given that there > is apparently no method like Cache.Clear() or Cache.Items.Cle ar()? Or
> am I > missing an easier way to do it?
>
> string currentKey= "";
> System.Collecti ons.IDictionary Enumerator cacheContents =
> System.Web.Http Context.Current .Cache.GetEnume rator();
> while (cacheContents. MoveNext()) {
> currentKey = cacheContents.K ey.ToString();
> System.Web.Http Context.Current .Cache.Remove(c urrentKey);
> }
>
> Thanks!
>
> -GH
>
>



Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5788
by: Varun | last post by:
Hello I am trying to make the items in my combobox be removed if they are present in my array I cant however get my code to work. The values are read into my combobox using a datareader. I then want to remove items from the items collection of the combobox if they are in my array. Here is what i try If i > 0 The For i= 0 To (MyArray.Count - 1 Combobox1.Items.Remove(MyArray Next End I
3
28709
by: Filippo P. | last post by:
Hi there, I have a menu (Collection) that needs to be trimmed based on security access of the logged user. protected void AdjustMenuBasedOnUserSecurity(Items ItemsList) { foreach (Item i in ItemsList) {
0
5411
by: Frawls | last post by:
Hi, This is concerned with System.Web.UI.WebControls.DropDownList I am having problems creating a method which will remove list items from a preloaded dropdownlist. This dropdown is loaded when the page loads and the items are pulled from a database. I want to create a method which is called on the page load and will remove certain items from the dropdown list. I want the method to loop
2
1945
by: Curious | last post by:
Hi, I am removing problems but I am having a problem. The code below is the code being used to remove items from the listview. ListViewItem oldItem = listViewAllStates.SelectedItems; listViewNextStateSelected.Items.Remove(oldItem); My problem occurs in the following scenario (example): Initially ListView empty
2
4878
by: Milsnips | last post by:
hi there, i have the following HTML code: -------------------------- <asp:DropDownList id="hddList" runat="server"> <asp:ListItem Value="1">Item 1</asp:ListItem> <asp:ListItem Value="2">Item 2</asp:ListItem> <asp:ListItem Value="3">Item 3</asp:ListItem> <asp:ListItem Value="4">Item 4</asp:ListItem> <asp:ListItem Value="5">Item 5</asp:ListItem>
17
2714
by: Eric_Dexter | last post by:
def simplecsdtoorc(filename): file = open(filename,"r") alllines = file.read_until("</CsInstruments>") pattern1 = re.compile("</") orcfilename = filename + "orc" for line in alllines: if not pattern1 print >>orcfilename, line I am pretty sure my code isn't close to what I want. I need to be able
0
1370
by: mharness | last post by:
Hello, Under most circumstances I don't have any trouble removing items from a dropdownlist but this time it's not working. I have a ddl that list items which, when choosen are added to a gridview on the same page and removed from the ddl so that they can only be added once. What I want to do and can't seem to make work is the code that removes the ddl items that are already on the gridview at page load.
0
1212
chathura86
by: chathura86 | last post by:
hi, i want to remove selected items from a list box this is the code i'v used Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click, lstSelNum.DoubleClick For Each i As Integer In lstSelNum.SelectedIndices txtSearch.Text += i & " - " lstSelNum.Items.RemoveAt(i)
0
7728
by: vivek kapile | last post by:
Title: Javascript for Adding & Removing Items from a one Listbox to another Author: Vivek Kapile Email: snipped Language: JavaScript Platform: Javascript in ASP.net Technology: Used in ASP.net Level: Beginner Introduction This code will help for the begineers, who want to learn, how to move the the items from one list box to another listbox with up and down facility.
0
8874
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9092
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6695
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6000
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4775
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3212
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2622
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.