subhashini
(Moderator):
The chat starts at 5.00 pm IST
subhashini (Moderator):
hello everbody . A very good evening to all of you.
subhashini (Moderator):
welcome to today's chat on ASP.NET caching Features
subhashini (Moderator):
We have Saravana P Kumar with us today
subhashini (Moderator):
Saravana currently works for Hewlett-Packard in Technology and Innovation
Leadership Group. He loves to work with technology that fascinates
him, .NET being his favorite.
subhashini (Moderator):
He co-hosts www.ExtremeExperts.com
, which is a collaborative knowledge base of Microsoft technology
related articles, tools, code snippets and much more. He has his
blog at <http://dotnetjunkies.com/WebLog/saravana>.
subhashini (Moderator):
Now before we start a few chat rules
Saravana (Expert):
Hi all, Welcome to the chat on ASP.NET Caching…
subhashini (Moderator):
Please refrain from sending any private messages to the expert
subhashini (Moderator):
But these rules will leave the chat broken if you don't adhere to
it.
subhashini (Moderator):
Chat Procedures:
This chat will last for one hour. During this hour, our Experts
will respond to as many questions as they can. Please understand
that there may be some questions we cannot respond to due to lack
of information or because the information is not yet public. We
encourage you to submit questions for our Experts. We ask that you
stay on topic for
subhashini (Moderator):
the duration of the chat. This helps the Guests and Experts follow
the conversation more easily. We invite you to ask off topic questions
after this chat is over.
subhashini (Moderator):
Once again , please refrain from sending private messages
subhashini (Moderator):
So let's get the chat rolling.
subhashini (Moderator):
welcome Saravana
Saravana (Expert):
Hi
Saravana (Expert):
Welcome to this chat
Saravana (Expert):
In this chat we are going to discuss about ASP.NET Caching features
and its enhancements in asp.net 2.0.
Saravana (Expert):
First I will give an introduction about ASP.NET Caching feature
(15 mins), then I will take up the questions on that (20 mins).
Saravana (Expert):
Finally I will cover caching enhancements in ASP.NET 2.0(15 mins)
.
Saravana (Expert):
Before we start with asp.net caching feature, I will explain what
is caching why we need to use caching in our application
Saravana (Expert):
Caching is the technique of storing frequently used resources in
a place where they can be accessed quickly.
Saravana (Expert):
In case of web application, either in browser cache or in proxy
or in web server...
Saravana (Expert):
If caching is used effectively, then it can improve performance,
scalability and availability of the application extensively
Saravana (Expert):
Now we will see how we can implement caching using ASP.NET
Saravana (Expert):
ASP.NET supports three types of caching.
- Page Output Caching
- Partial Page Caching
- Data Caching
Saravana (Expert):
We will see one by one, we will start with output caching.
Saravana (Expert):
Output caching caches the entire content of a webpage. This caching
can be enabled in a web page using ouputcache directive of asp.net
page
Saravana (Expert):
Note: I am not going to explain with code samples..
Saravana (Expert):
if u need then tell me, i will post the code to explain that feature
Saravana (Expert):
Location: Using this attribute you can mention where you want to
store your cache. Possible options are client (browser cache), proxy
server and web server
Saravana (Expert):
Duration: Using this attribute you can mention how much time you
want to store the cache after which it will be automatically removed
from cache
Saravana (Expert):
VaryByParam: Using this attribute you can cache different version
of the same page based on the input parameters sent through the
HTTP POST/GET
Saravana (Expert):
VaryByHeader: Using this attribute you can cache the multiple copies
of page based on HTTP headers
Saravana (Expert):
VaryByCustom: Using this attribute you can cache the multiple copies
of page based on a custom string
Saravana (Expert):
Next is fragment caching which is also called partial page caching
Saravana (Expert):
Caching the entire page isn’t always possible, you might have
few regions in the page which changes very frequently. In this case,
you can use fragment caching.
Saravana (Expert):
Fragment allows caching regions of the page using user controls.
Saravana (Expert):
Fragment caching can be enabled by defining output cache directive
in user control similar to output cache directive in web form
Saravana (Expert):
Most of the attributes supported by page output caching is also
supported in fragment caching.
Saravana (Expert):
But location attribute of output caching is not supported for fragment
caching, as caching has to done in web server for fragment caching
Saravana (Expert):
VaryByControl and Shared attributes are supported only in fragment
caching.
Saravana (Expert):
VaryByControl : This attribute allows you to vary the cache based
on user control properties
Saravana (Expert):
Shared attribute: Using this attribute you can specify whether user
control cache can be shared among the aspx pages where that user
control is used.
Saravana (Expert):
Only thing you should take care while using fragment caching is,
you shouldn’t programmatically access user control that is
in cache.
Saravana (Expert):
Cached user controls are not added to page control tree, so if you
try to access that control it will throw an exception.
Saravana (Expert):
Finally Data Caching..
Saravana (Expert):
There are various ways for data caching in asp.net like sessions,
application and cache object.
Saravana (Expert):
Depending upon your requirement you can choose between these data
caching options.
Saravana (Expert):
If you want to store some variable which varies for each user, then
you can go for session object.
Saravana (Expert):
Application and Cache object works in the same way. But cache objects
support other features like dependencies, scavenging and expiration
policy which is not supported in application object. Application
variable is supported only for backward compatible.
Saravana (Expert):
File dependency, Key dependency and Time based dependency are dependency
objects supported in ASP.NET 1.1 for data cachine
Saravana (Expert):
But much requested dependency is SQL Dependency, which is not supported
in ASP.NET 1.1. But there are many workarounds available. Here I
am mentioning two ways to achieve this,
Saravana (Expert):
One way is to create trigger in the table where you have the data.
In the trigger call an extended stored procedure using which you
can change some data in a file. In asp.net set the dependency caching
to that file. So when the data in the table changes, trigger will
fire which will call extended SP. This SP will update the file and
hence cache is invalidated.
Saravana (Expert):
Other way is to maintain a table “changelist” which
stores the list of the tables you want to check for changes. Then
have a trigger in each table, if any data changes in the table.
Trigger will fire and update the changelist table. Have a windows
service which will verify this table continuously to verify if there
is any change. If there is any change, it will invalidate cache
correspondingly.
Saravana (Expert):
I am going to list down some of the scenarios where you can use
caching..
Saravana (Expert):
If the generated page generally stays the same, but there are several
tables shown within the output that change regularly.
Saravana (Expert):
Which caching type you will use????
Saravana (Expert):
Use Fragment Caching in this situation. Cache the portions of the
page that remain somewhat static, while dynamically generating the
table contents. Also consider using DataCaching for storing some
individual objects.
Saravana (Expert):
The generated page constantly changes, but there are a few objects
that don’t change very often.
Saravana (Expert):
Use Data Caching for the objects.
Saravana (Expert):
The generated page changes every few hours as information is loaded
into a database through automated processes.
Saravana (Expert):
Use Output Caching and set the duration to match the frequency of
the data changes.
Saravana (Expert):
Things to consider when you implement ASP.NET caching,
Saravana (Expert):
1. Where do you want to store the cache? - Location
2. For how much time you want to store the cache - Duration
3. When do you want to invalidate the cache?
Saravana (Expert):
To measure how your caching methodology performs, you can measure
it using performance counters. Various counters like Cache Total
Entires, Cache Total hits, etc are available in ASP.NET 1.1.
Saravana (Expert):
With this I am completing the brief on ASP.NET Caching in .Net framework
1.1. We will have small discussion about this topic, then I can
cover Caching enhancement in Whidbey(.Net Framework 2.0)
Saravana (Expert):
You can post your questions now…
Saravana (Expert):
Q: whats the best option for auditing?
A: Auditing is not supported by default in asp.net 1.1. But
it is supported in 2.0. for more details refere this link,
Saravana (Expert):
Q: whats the best option for auditing?
A: http://beta.asp.net/quickstart/aspnet/doc/monitoring.aspx
Saravana (Expert):
Q: Is Page Output Caching means the pages cached in history
object of the brower?
A: I think i covered that part...
Saravana (Expert):
Q: wat if cookies is disabled in my browser?
A: ASP.NET Caching doesnt depends on cookies.. can you explain
more...
Saravana (Expert):
Q: can u put some light on caching of datagrid.
A: You can either use fragment caching or data caching in
case of datagrid. You can place you datagrid in a user control and
cache the user control alone. Or use data cachine and cache the
datasource of datagrid.
Saravana (Expert):
Q: shall we apply varybycontrol applies to customcontrols
also
A: no. Usercontrol has inbuild support for this.
Saravana (Expert):
Q: While caching in ASP.net is it possible to cache a part
of a page
A: Yes, use fragment caching
Saravana (Expert):
Q: can the cache dependency be placed against SQL server
in ASP.NEt 2.0? If yes, how?
A: Yes, will cover it in next part
Saravana (Expert):
Please dont post any private messages...that might halt the chat.
Saravana (Expert):
Q: Can i maintain more than one type of caching in single
application?
A: Yes, you can. Even in one web page, you can have more
than one type of caching
Saravana (Expert):
Q: The worker process (aspnet_wp.exe) grows by almost 15
MB when the user logs on to our asp.net application. Is this means
default caching happens and memory grows.
A: Memory of the application can grow based on various reason.
You can use caching performance counters to find out whether it
is because of caching
Saravana (Expert):
Q: SQL Cache dependancy can be achieved by using triggers.
Then what about the perfomance of the application, as using triggers
will affect the performance
A: Cache dependency doesnt affect the performance of the
application as it is happening asynchronously
Saravana (Expert):
Q: suppose there is a GRID, which has some columns &
there are 1000 rows, how to cache the Grid data?
A: Caching 1000 rows requires more memory. so dont go for
data caching.. If the data wont change very frequently, then you
can go for either partial caching or output caching where the output
of the page is cached
Saravana (Expert):
Q: is it possible to have a separate Cache server, where
we keep data & use it on the web server on the Need basis?
A: Yes, you can implement your own caching methodlogy. check
out this link for caching architecure by microsoft.
Saravana (Expert):
Q: i have a page which retrieves data from a database server
. now if i cache the output of the page, and if the client requests
for that page again, will the code execute to hit the db again or
will the page be served from the cache
A: it will be served from the cache. it wont fetch it from
db
Saravana (Expert):
Q: can u give us resources from where we could do RND in
caching, i mean sites
A: At the end of this chat i will give links to many articles..
i have lots of links
Saravana (Expert):
Q: By default caching is enabled in asp.net, So i should
use the output cache option only if i need to expire the cache for
a pge explicitly, am i right ?
A: by default caching is not enabled.
Saravana (Expert):
Q: Can we get code samples for fragment caching..?
A:
In user control,
<%@ Control %>
<%@ OutputCache VaryByParam="none" Duration="10"
%>
<Font size=6> Fragment Cache created: <Font color=red><B><%=Now()%></B></Font>
In web page,
<%@ Page %>
<%@ Register TagPrefix="Fragment" TagName="Simple"
Src="fragment_vb.ascx" %>
<Script runat=server>
Public Sub Page_Load(sender As Object, e As EventArgs)
CreatedStamp.InnerHtml = Now()
End Sub
</Script>
<Font size=6>Fragment Cache Simple example
<P>
<HR size=1>
<Fragment:simple id="UserCon1" runat=server />
<hr size=
subhashini (Moderator):
Sorry for this interruption
subhashini (Moderator):
pleas etry relogging into the chat , if you are having issues
subhashini (Moderator):
The chat transcript would be avilable on the link http://www.microsoft.com/india/communities/chat/Transcripts.aspx
soon
Saravana (Expert):
Q: is it possible to have a separate Cache server, where
we keep data & use it on the web server on the Need basis?
A: I didnt give the link, here it is..http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/CachingArch.asp
Saravana (Expert):
Q: are there graphs to support how caching help performance
of the site.
A: Yes, i have. I cant post it in chat. It will surely improve
by 2-3 times
Saravana (Expert):
Q: I can see my application folders saved under the folder
(C:\WINNT\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files).
Is this realted ot caching
A: That is nothing to do with caching. Its how ASP.NET compilation
works.
Saravana (Expert):
Q: Can I use Caching In my Service Agents?
A: How your service agents is implemented? windows service
or web service
Saravana (Expert):
Q: when to use caching and application variables
A: Use caching always. Application variable supported only
for backward compatibility. One reason i will go for application
variable is store a data which never changes
Saravana (Expert):
Q: WebService
A: Yes, you can use.
Saravana (Expert):
Folks, keep posting your question
Saravana (Expert):
i will start with ASP.NET 2.0 caching enhancements intro
Saravana (Expert):
Is everyone with me????
Saravana (Expert):
One of the important enhancement in asp.net 2.0/whidbey is sqldependency
Saravana (Expert):
SQL Dependency is supported out of the box.
Saravana (Expert):
Just you need to set one property to enable sql dependency in ASP.NET
2.0 in your web page.
<%@ outputcache duration="9999" varybyparam="none"
sqldependency="MyDatabase:Products" %>
Saravana (Expert):
MyDatabase is config key name which mentions about database details
Saravana (Expert):
Products is table name in which you want to set dependency
Saravana (Expert):
SQL Depedency for SQL Server 2000 database and Yukon database work
differently,
Saravana (Expert):
For SQL Server 2000, SQL Dependency works based on pull model. As
we discussed earlier one service will constanly looks for changes
in database
Saravana (Expert):
Approach 2 which i mentioned previously to implement sqldepedency
in asp.net1.1 application.
Saravana (Expert):
But in Yukon, it is push model. If anything changes in database,
it will be notified to ASP.NET. Hence it performs better.
Saravana (Expert):
In Yukon, you can even set SQL Dependency to particular SQL Procedure
output or selected rows in a table.
Saravana (Expert):
Next enhancement is Post Cache Substitution
Saravana (Expert):
This feature allows to add the dynamic content to the cached page.
This feature is similar to fragment caching, but it works backwards.
Saravana (Expert):
In fragment caching, you cache certain portion of the page but the
page is created every time. Here you cache the entire page, but
certain portion of the page is created dynamically.
Saravana (Expert):
New control named <asp:substitution> is introduced to implement
this feature.
Saravana (Expert):
Next enhancement is, you can extend the Cachedependency class.
Saravana (Expert):
Its not sealed, so you can extend this class.
Saravana (Expert):
This is how sqldependency is implemented. It is extended from cachedepedency
class
Saravana (Expert):
So you can create own dependency class like oracle database dependency
or web service dependency by deriving from Cachedependency class.
Saravana (Expert):
Other two enhancements are
Saravana (Expert):
Caching to Disk
Saravana (Expert):
and Output Cache profile
Saravana (Expert):
In ASP.NET 1.1, you have only one option to store your cache in
memory. But in ASP.NET 2.0 you can store your cache to disk also
by using DiskCacheable property in outputcache directive.
Saravana (Expert):
So you no need to worry about memory problems with cache
Saravana (Expert):
but there will be a slight performance degradation since it is stored
in disk compared to memory
Saravana (Expert):
Output Cache profile
Saravana (Expert):
Cache profile allows you to centrally control cache settings from
config files. For example you can define an output profile in config
file with duration as 60 secs. In the outputcache directive you
can mention this profile name using CacheProfile property. Then
if you want to change this duration, you can just change it in config
file. You no need to change it in all the pages.
Saravana (Expert):
all these enhancements are very useful which were missing in ASP.NET
2.0
Saravana (Expert):
With this i am finishing with my intro part, you can post your questions
now...
Saravana (Expert):
At the end of this session, i will links to resources on caching
Saravana (Expert):
Cachedepdency class is coming under System.Web.Caching namespace
Saravana (Expert):
Q: at times we need to restart the IIS server. will the cached
data gets flushed out in this case ?
A: Yes, cached data is stored in app domain. Hence when you
restart you application, the app domain is recycled. Hence you will
loose all your cached data
Saravana (Expert):
Q: When we are trying to clear variables from cache the effect
is not seen in the worker process. Is that because the worker process
reuses the memory later.
A: Memory will be immediately released, needs to check on
this
Saravana (Expert):
Q: what is the default duraton of cache expiry
A: There is no default value for cache expiry. Duration is
mandatory field. If you do not include it, a parser error occurs
Saravana (Expert):
Q: Can i use cached data across App Domain(means is it serializable),
if want to access in case of remoting
A: You can use asp.net caching. But you can implement you
own caching methodology. Check out Microsoft Caching Architecture
guide. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/CachingArch.asp
Saravana (Expert):
Q: where Caching occupy the disk space? is it WebServer or
aspnet worker process or client machine?
A: Depending upon location attribute in output cache, this
will be decided
Saravana (Expert):
Q: what is the cache limit and what is the viable option
for client side and server side cache?what is the scope of shared
caching that is since it is stored in app domain can i access it
from appdomain while the first finished execution?
A: There is no limit for cache. Scope of the shared caching
is only within domain.
Saravana (Expert):
Q: how concurrency is handle in sql cachedependence?
A: SQL Cache Depedency doesnt need to worry about concurrency.
Can you explain more on this
Saravana (Expert):
Q: if location is set to be WebServer then is it occupy more
space of the aspnet woker process?
A: if it set to webserver. It will be stored in web server
cache which can be used by all the users
Saravana (Expert):
Q: what is the viable option for client side and server side
cache?on what criteria u decide the same?
A: Depending upon network bandwidth, you can decide on this.
If it is client side caching, request no need to go to server and
respone also no need to come from server. hence network traffice
will be less
Saravana (Expert):
Q: what happen to cached data if aspnet_wp process recycled.
Will it be lost or still perisists.....
A: It will be lost. Since it is stored in app-domain memory
subhashini (Moderator):
we have the last 10 mins left for the chat to conclude
Saravana (Expert):
Q: when to use Cache and when to use Application object
A: This question is already answered. Can you check it
subhashini (Moderator):
hence request all of you to post your queries to saravana@extremeexperts.com
Saravana (Expert):
Q: In Page Output Caching->VaryByParam: Can by any way
we restrict how many version of page output cache can be maintained..
A: No, we cant control it. Its depends on VaraByParam attribute
values..
Saravana (Expert):
Q: what about data caching?
A: We covered data caching already. You can use Cache API
to implement data caching in asp.net Do you have any speific question
on data caching?
Saravana (Expert):
ASP.NET 1.1 Caching
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcacheapis.asp
ASP.NET 2.0 Caching
<http://msdn.microsoft.com/asp.net/whidbey/default.aspx?pull=/library/en-us/dnvs05/html/aspnetwhidbey_caching.asp>
<http://msdn.microsoft.com/asp.net/whidbey/default.aspx?pull=/library/en-us/dnvs05/html/cachingnt2.asp>
Caching Application block
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/caching1.asp>
Microsoft Caching Architecture
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/CachingArch.asp>
Implementing custom cache in asp.net 1.x
<http://msdn.microsoft.com/msdnmag/issues/04/07/CuttingEdge/>
Implementing SQL Dependency in asp.net 1.x
<http://msdn.microsoft.com/msdnmag/issues/03/04/wickedcode/>
Saravana (Expert):
I have posted few links here with respect to caching.
Saravana (Expert):
If you need any resourse on particular feature, you can ping me...
Saravana (Expert):
Any questions?
Saravana (Expert):
Chat is going to end...
Saravana (Expert):
saravana@extremeexperts.com
Saravana (Expert):
You can mail regarding any doubts in .NET. I will try my level best
to answer..
subhashini (Moderator):
So this brings us to the end of the chat
subhashini (Moderator):
hope all of you found the chat informative and useful
subhashini (Moderator):
thanks Saravana for being so quick and effective in your explanations
and relies
subhashini (Moderator):
thanks all of you for taking out tiem from your busy schedule
subhashini (Moderator):
to attend this chat
Saravana (Expert):
Thanks Subhashini..
Saravana (Expert):
Thanks all...
subhashini (Moderator):
thsi chat happens every wednesday
subhashini (Moderator):
bookmark the url http://www.microsoft.com/india/communities/chat/default.aspx
for forthcoming chats
subhashini (Moderator):
once again thanks all of you
subhashini (Moderator):
teh chat transcript will be available on teh site soon
subhashini (Moderator):
have a lovely evening
subhashini (Moderator):
http://www.microsoft.com/india/communities/chat/Transcripts.aspx
- chat transcripts
Saravana (Expert):
Again..Thanks all for participating in this chat. If you have any
question, mail me
Saravana (Expert):
Bye, have a nice evening.
|