473,396 Members | 1,970 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,396 software developers and data experts.

How to cache links?

How do I add a string to the cache so that it updates if the string
source changes? CacheDependency() seems to want an absolute path. My
string is a full http link.

Thanks,
Brett

Jan 2 '07 #1
8 1411
Brett,

I will assume your link changes due to a change in the data on the
backend.

Whenever you add an item to the cache you can attach the
CacheDependency. This could be a dependency on a database table, a
file or another kind of dependency. I am not sure what you mean by it
requiring a full path. When you add an item to the Cache you use a
unique identifier for the item with the item being any kind of object.
In this case a string will obviously work.

I have often added items to the cache without a dependency because I
just want to hold onto it for a the length of the timeout or until the
cache removes it to clear space for newly added items. Using the cache
without a dependency in this way is sufficient to reduce load on the
database, especially when I know the data is not changing. But if the
data does change you can monitor it with a dependency and attach that
dependency to the cached item.

Be sure to use Cache.Insert(...) instead of Cache.Add(...) and set up
your dependency to do as you want. The Insert replaces an existing
item with the same key. The trick is using a unique key which you can
know before pulling the data used to assemble the cached item. I use a
prefix to give it some context and then usually append the primary key
or query parameters to that prefix to create the key.

See SQL Cache Dependencies here...

http://msdn2.microsoft.com/en-us/lib...cy(VS.80).aspx
http://msdn2.microsoft.com/en-us/lib...cy(VS.80).aspx

I hope this is what you wanted to know. If not, let me know.

Brennan Stehling
http://brennan.offwhite.net/blog/
brett wrote:
How do I add a string to the cache so that it updates if the string
source changes? CacheDependency() seems to want an absolute path. My
string is a full http link.

Thanks,
Brett
Jan 2 '07 #2
Hi Brennan,

It isn't related to SQL Server. The URL I'm using is defined in a
class called Utilities.cs. It's a static string in that close. I load
the URL into the cache in Application_Start() of Global.asax. If I
need to change this URL, I'd like that updated in the cache with
mininal impact to the web app. So the change will occur by manual
intervention. I'm not sure if CacheDependency() is what I should use
in that case or how to use it in that case.

By full link, I mean something similar to
"http://abc.com/somepage.aspx". It's absolute in other words. Any
suggestions?

Thanks,
Brett

Jan 2 '07 #3
You might be better off keeping the value in an xml file, and reading it
from there - that way you could put a dependency on the cache automatically
invalidating if the file was updated and refreshing the value.

http://aspnet.4guysfromrolla.com/articles/121802-1.aspx
--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog
"brett" <ac*****@cygen.comwrote in message
news:11**********************@a3g2000cwd.googlegro ups.com...
Hi Brennan,

It isn't related to SQL Server. The URL I'm using is defined in a
class called Utilities.cs. It's a static string in that close. I load
the URL into the cache in Application_Start() of Global.asax. If I
need to change this URL, I'd like that updated in the cache with
mininal impact to the web app. So the change will occur by manual
intervention. I'm not sure if CacheDependency() is what I should use
in that case or how to use it in that case.

By full link, I mean something similar to
"http://abc.com/somepage.aspx". It's absolute in other words. Any
suggestions?

Thanks,
Brett

Jan 2 '07 #4
this what you would create a cache dependency class for. when you change
the static value, set the status in your dependency class. though if its
a static string I'm not sure what the cache is for.

-- bruce (sqlwork.com)

brett wrote:
Hi Brennan,

It isn't related to SQL Server. The URL I'm using is defined in a
class called Utilities.cs. It's a static string in that close. I load
the URL into the cache in Application_Start() of Global.asax. If I
need to change this URL, I'd like that updated in the cache with
mininal impact to the web app. So the change will occur by manual
intervention. I'm not sure if CacheDependency() is what I should use
in that case or how to use it in that case.

By full link, I mean something similar to
"http://abc.com/somepage.aspx". It's absolute in other words. Any
suggestions?

Thanks,
Brett
Jan 2 '07 #5
Brett,

Also be aware that since this is a cache it can drop items out anytime
for multiple reasons. You can handle the OnRemove event so you can add
a fresh copy back onto the cache so you always know it is there.

It sounds like using the cache may not be the right approach for you.
If you can detect when something changes and can then update it at that
time you could just set a static property which you can access in your
web application. That way you know it will always be available.

Brennan

bruce barker wrote:
this what you would create a cache dependency class for. when you change
the static value, set the status in your dependency class. though if its
a static string I'm not sure what the cache is for.

-- bruce (sqlwork.com)

brett wrote:
Hi Brennan,

It isn't related to SQL Server. The URL I'm using is defined in a
class called Utilities.cs. It's a static string in that close. I load
the URL into the cache in Application_Start() of Global.asax. If I
need to change this URL, I'd like that updated in the cache with
mininal impact to the web app. So the change will occur by manual
intervention. I'm not sure if CacheDependency() is what I should use
in that case or how to use it in that case.

By full link, I mean something similar to
"http://abc.com/somepage.aspx". It's absolute in other words. Any
suggestions?

Thanks,
Brett
Jan 2 '07 #6
>>though if its
a static string I'm not sure what the cache is for.
To avoid disk hits. I have a number of static links used on my site.
Every time a page using these links loads, it will hit the static
reference. Caching avoids that.

Brett

Jan 2 '07 #7
I build these links initially. They are build in three parts:

http + rootdomain (depends on server I'm using) + directory and page

I can put the directory/page part in the XML file. Then build the rest
in the Refresh() of Global.asax. Then I write over the existing cache
values. When the XML file changes because I've updated a link, the
CacheDependency() will fire, causing the Refresh() method to execute
and rebuild all links. Should that work fine?

Thanks,
Brett

Jan 2 '07 #8
That may be more work than you really need.

Instead you can create a simple UserControl which reads in the contents
of your file and places it into a LiteralControl as the Text property.
You may want to use the OutputCache, but that only has the
SqlCacheDependency. So you will have to manage the cached item and
attach your file cache dependency.

See the example at the link below where it uses the filename to create
the CacheDependency. That sounds exactly what you want.

http://msdn2.microsoft.com/en-us/lib...ependency.aspx

It should work with less than 10 lines of code.

Brennan Stehling
http://brennan.offwhite.net/blog/

brett wrote:
I build these links initially. They are build in three parts:

http + rootdomain (depends on server I'm using) + directory and page

I can put the directory/page part in the XML file. Then build the rest
in the Refresh() of Global.asax. Then I write over the existing cache
values. When the XML file changes because I've updated a link, the
CacheDependency() will fire, causing the Refresh() method to execute
and rebuild all links. Should that work fine?

Thanks,
Brett
Jan 3 '07 #9

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

Similar topics

21
by: Bill H | last post by:
I have a routine that displays 60 items (with thumbnails) per page. You can click any item and displays a new page with item details. When the user back pages it runs the query again to display all...
2
by: Ben | last post by:
Hi all, I have written a web server that listens for requests: class MyHandler(BaseHTTPRequestHandler): def do_GET(self): if (self.path)=='/': data=makeList() else:
7
by: A.M | last post by:
Hi, How can I change the duration of user control's cache inside asp.net's C# code? Any help would be apprecited, Alan
1
by: martyn_wynne | last post by:
I'm am finding it hard to find in black and white the answer to the following question, are files like javascipt and css files cachabled when on a pure https site? Any links to full explinations...
14
by: Tom.PesterDELETETHISSS | last post by:
Hi, I think this question requires an in depth understanding of how a browser cache works. I hope I can reach an expert here. I may have found a quirk in the asp.net documentation or I don't...
2
by: Enosh Chang | last post by:
Hi all: I want to use System.Web.Caching.Cache in my web application, but I want to know the lifecycle of Cache (depending on Page, Session or Application ...). Thanks! Enosh
3
by: poolieweb | last post by:
I have created a custom user control which creates a ASPxMenu ( Same fucntion as standard menu control) from data retreved from a webservice (Reporting Services) which deals with user access. This...
1
by: ll | last post by:
I have a page in in ASP which lists static links to PDF files. When users click on the links, they receive the following message: right-clicking on the link and selecting "save target as"...
10
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... We've been trying to migrate our asp.net apps off older, underpowered hardware to newer, bigger boxes but when we do, we see our databases start to melt. When I started to look into it,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
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...

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.