By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,570 Members | 970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,570 IT Pros & Developers. It's quick & easy.

using cache application block in web application

P: n/a
has anyone managed to use cache application block in a web application?

thanks
stanley
Jul 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Yes.

What's wrong

- Joris

"Stanley" <St*****@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com...
has anyone managed to use cache application block in a web application?

thanks
stanley

Jul 21 '05 #2

P: n/a
I have put the caching application block setting in the web.config file but
when i call CacheManager.GetCacheManager(), i got an exception
("Configuration information is not available"). Following is the CAB settings:

<configSections>
<section name="CacheManagerSettings"
type="Microsoft.ApplicationBlocks.Cache.CacheConfi gurationHandler,Microsoft.ApplicationBlocks.Cache" />
<section name="CacheService"
type="Microsoft.ApplicationBlocks.Cache.CacheConfi gurationHandler,Microsoft.ApplicationBlocks.Cache" />
</configSections>

<!-- CACHING BLOCK SETTINGS -->
<CacheManagerSettings>
<StorageInfo AssemblyName="Microsoft.ApplicationBlocks.Cache"
ClassName="Microsoft.ApplicationBlocks.Cache.Stora ges.SingletonCacheStorage"
Mode="InProc" Validated="false" Encrypted="false" />
<ScavengingInfo AssemblyName="Microsoft.ApplicationBlocks.Cache"
ClassName="Microsoft.ApplicationBlocks.Cache.Scave nging.LruScavenging"
UtilizationForScavenging="80" MaximumSize="200" />
<ExpirationInfo Interval="15" />
</CacheManagerSettings>

<CacheService>
<StorageInfo>
<AssemblyName>Microsoft.ApplicationBlocks.Cache</AssemblyName>
<ClassName>Microsoft.ApplicationBlocks.Cache.Stora ges.SingletonCacheStorage</ClassName>
<Mode>InProc</Mode>
<MaximumSize>200</MaximumSize>
</StorageInfo>
<Scavenging>
<Algorithm>
<AssemblyName>Microsoft.ApplicationBlocks.Cache</AssemblyName>
<ClassName>Microsoft.ApplicationBlocks.Cache.Scave nging.LruScanvenging</ClassName>
</Algorithm>
<MemoryPollingPeriod>60</MemoryPollingPeriod>
<UtilizationForScavenging>80</UtilizationForScavenging>
</Scavenging>
<ExpirationCheckInterval>2</ExpirationCheckInterval>
</CacheService>
"Joris Dobbelsteen" wrote:
Yes.

What's wrong

- Joris

"Stanley" <St*****@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com...
has anyone managed to use cache application block in a web application?

thanks
stanley


Jul 21 '05 #3

P: n/a
Do you happen to use the "Commerce Server"? With that thing I don't have
any experience (sorry for that)...
I couldn't find anything in the MSDN directly and a search to "CacheManager"
resulted in articles from the Commerce Server 2000/2002...
I did use ASP.NET Caching quite extensively and also added some code to
reduce the bandwidth even further (returning 304 quite frequently).

I believe you are really doing it the hard way. My code to support ASP.NET
caching is quite small

(on an object that derives from System.Web.UI.Page, C#)
Object obj = Cache["MyNeededObject"];
if (obj = null)
{
obj = ...
Cache.Add("MyNeededObject", obj, DateTime.Now().AddMinutes(5), null);
}
......

Eventually I moved the SQL stuff to a different class, where the constructor
of that class required you to pass the cache object with it.

You can also set the caching of a page (really recommended, as proxies on
the way do that too).
in Response.Caching object I believe.
Check out
http://hoogendroog.ath.cx/ - first time costs time, second load should be
very fast
http://hoogendroog.ath.cx/default.aspx/peekcache - shows the current ASP.NET
cache contents
(If the second one doesn't show any items, at least visit the home page)

For the first page, when looking at the HTTP protocol you can sometimes see
the 'Expires' header counting down, ASP.NET is caching in this case.
If not, my code is returning the 304 header (don't forget to include the
If-Modified-Since request header set to the received Last-Modified response
header).

- Joris
<snip>
Jul 21 '05 #4

P: n/a
Do you happen to use the "Commerce Server"? With that thing I don't have
any experience (sorry for that)...
I couldn't find anything in the MSDN directly and a search to "CacheManager"
resulted in articles from the Commerce Server 2000/2002...
I did use ASP.NET Caching quite extensively and also added some code to
reduce the bandwidth even further (returning 304 quite frequently).

I believe you are really doing it the hard way. My code to support ASP.NET
caching is quite small

(on an object that derives from System.Web.UI.Page, C#)
Object obj = Cache["MyNeededObject"];
if (obj = null)
{
obj = ...
Cache.Add("MyNeededObject", obj, DateTime.Now().AddMinutes(5), null);
}
......

Eventually I moved the SQL stuff to a different class, where the constructor
of that class required you to pass the cache object with it.

You can also set the caching of a page (really recommended, as proxies on
the way do that too).
in Response.Caching object I believe.
Check out
http://hoogendroog.ath.cx/ - first time costs time, second load should be
very fast
http://hoogendroog.ath.cx/default.aspx/peekcache - shows the current ASP.NET
cache contents
(If the second one doesn't show any items, at least visit the home page)

For the first page, when looking at the HTTP protocol you can sometimes see
the 'Expires' header counting down, ASP.NET is caching in this case.
If not, my code is returning the 304 header (don't forget to include the
If-Modified-Since request header set to the received Last-Modified response
header).

- Joris
<snip>
Jul 21 '05 #5

P: n/a
hi Joris,

when i set the expiration and itemremovedcallback when i add the item to
cache. the callback only executed once. in this itemremovedcallback function,
i added the item back to cache again.

how come it would not execute the callback on the second time?
"Joris Dobbelsteen" wrote:
Do you happen to use the "Commerce Server"? With that thing I don't have
any experience (sorry for that)...
I couldn't find anything in the MSDN directly and a search to "CacheManager"
resulted in articles from the Commerce Server 2000/2002...
I did use ASP.NET Caching quite extensively and also added some code to
reduce the bandwidth even further (returning 304 quite frequently).

I believe you are really doing it the hard way. My code to support ASP.NET
caching is quite small

(on an object that derives from System.Web.UI.Page, C#)
Object obj = Cache["MyNeededObject"];
if (obj = null)
{
obj = ...
Cache.Add("MyNeededObject", obj, DateTime.Now().AddMinutes(5), null);
}
......

Eventually I moved the SQL stuff to a different class, where the constructor
of that class required you to pass the cache object with it.

You can also set the caching of a page (really recommended, as proxies on
the way do that too).
in Response.Caching object I believe.
Check out
http://hoogendroog.ath.cx/ - first time costs time, second load should be
very fast
http://hoogendroog.ath.cx/default.aspx/peekcache - shows the current ASP.NET
cache contents
(If the second one doesn't show any items, at least visit the home page)

For the first page, when looking at the HTTP protocol you can sometimes see
the 'Expires' header counting down, ASP.NET is caching in this case.
If not, my code is returning the 304 header (don't forget to include the
If-Modified-Since request header set to the received Last-Modified response
header).

- Joris
<snip>

Jul 21 '05 #6

P: n/a
"Stanley" <St*****@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
hi Joris,

when i set the expiration and itemremovedcallback when i add the item to
cache. the callback only executed once. in this itemremovedcallback function, i added the item back to cache again.
Your should NOT do that. Really, you should only cache data when you NEED
them.

The cache will expire objects not only when they expire, but also to
preserve the systems resources sometimes. It provides some priority mechnism
to deside what to remove when resources run out.

My software uses a class to load a dataset on-demand.
If its in cache, get it from cache, otherwise I execute the database query
and put the data in the cache.

Use the cache just like a web proxy does.
When you make the request it is either fetched from cache or from the
internet (and cached). When the web proxy runs out of space, it will clean
expired items. The ASP.NET cache works the same way.
how come it would not execute the callback on the second time?


When using the Add method, it will fail if a similair named item is in the
cache.
Use Insert to overwrite.
Ensure you specify the callback.

<snip>

Another interest might be using the Response.Caching object to ensure the
page is cached all over the internet (and with ASP.NET page caching too). It
has good facilities to prevent processing the page again, when its not
needed. (You can save processing power and network bandwidth when doing it
correctly).

- Joris
Jul 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.