using cache application block in web application

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

has anyone managed to use cache application block in a web application?

thanks
stanley
 
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.CacheConfigurationHandler,Microsoft.ApplicationBlocks.Cache" />
<section name="CacheService"
type="Microsoft.ApplicationBlocks.Cache.CacheConfigurationHandler,Microsoft.ApplicationBlocks.Cache" />
</configSections>

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

<CacheService>
<StorageInfo>
<AssemblyName>Microsoft.ApplicationBlocks.Cache</AssemblyName>
<ClassName>Microsoft.ApplicationBlocks.Cache.Storages.SingletonCacheStorage</ClassName>
<Mode>InProc</Mode>
<MaximumSize>200</MaximumSize>
</StorageInfo>
<Scavenging>
<Algorithm>
<AssemblyName>Microsoft.ApplicationBlocks.Cache</AssemblyName>
<ClassName>Microsoft.ApplicationBlocks.Cache.Scavenging.LruScanvenging</ClassName>
</Algorithm>
<MemoryPollingPeriod>60</MemoryPollingPeriod>
<UtilizationForScavenging>80</UtilizationForScavenging>
</Scavenging>
<ExpirationCheckInterval>2</ExpirationCheckInterval>
</CacheService>
 
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>
 
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?
 
Stanley said:
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
 
Back
Top