473,395 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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.Clear()? Or am I
missing an easier way to do it?

string currentKey= "";
System.Collections.IDictionaryEnumerator cacheContents =
System.Web.HttpContext.Current.Cache.GetEnumerator ();
while (cacheContents.MoveNext()) {
currentKey = cacheContents.Key.ToString();
System.Web.HttpContext.Current.Cache.Remove(curren tKey);
}

Thanks!

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

-- bruce (sqlwork.com)

"Guadala Harry" <GM**@NoSpam.com> wrote in message
news:OW**************@TK2MSFTNGP10.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.Clear()? Or am I
| missing an easier way to do it?
|
| string currentKey= "";
| System.Collections.IDictionaryEnumerator cacheContents =
| System.Web.HttpContext.Current.Cache.GetEnumerator ();
| while (cacheContents.MoveNext()) {
| currentKey = cacheContents.Key.ToString();
| System.Web.HttpContext.Current.Cache.Remove(curren tKey);
| }
|
| 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.com> wrote in message
news:OW**************@TK2MSFTNGP10.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.Clear()? Or am I
missing an easier way to do it?

string currentKey= "";
System.Collections.IDictionaryEnumerator cacheContents =
System.Web.HttpContext.Current.Cache.GetEnumerator ();
while (cacheContents.MoveNext()) {
currentKey = cacheContents.Key.ToString();
System.Web.HttpContext.Current.Cache.Remove(curren tKey);
}

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******@nospamtwcny.rr.com> wrote in message
news:OC**************@TK2MSFTNGP14.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.com> wrote in message
news:OW**************@TK2MSFTNGP10.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.Clear()? Or am I missing an easier way to do it?

string currentKey= "";
System.Collections.IDictionaryEnumerator cacheContents =
System.Web.HttpContext.Current.Cache.GetEnumerator ();
while (cacheContents.MoveNext()) {
currentKey = cacheContents.Key.ToString();
System.Web.HttpContext.Current.Cache.Remove(curren tKey);
}

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.com> wrote in message
news:uq**************@tk2msftngp13.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******@nospamtwcny.rr.com> wrote in message
news:OC**************@TK2MSFTNGP14.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.com> wrote in message
news:OW**************@TK2MSFTNGP10.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.Clear()? Or
> am I > missing an easier way to do it?
>
> string currentKey= "";
> System.Collections.IDictionaryEnumerator cacheContents =
> System.Web.HttpContext.Current.Cache.GetEnumerator ();
> while (cacheContents.MoveNext()) {
> currentKey = cacheContents.Key.ToString();
> System.Web.HttpContext.Current.Cache.Remove(curren tKey);
> }
>
> Thanks!
>
> -GH
>
>



Nov 18 '05 #5

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

Similar topics

3
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...
3
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...
0
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...
2
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;...
2
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...
17
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...
0
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...
0
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,...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.