Monday, May 25, 2009

Asp.Net Caching Part 1

Caching is a technique that temporarily stores valuable information in server memory so it can be reused.

Caching is often used to store information that's retrieved from a database, so they'll retrieve the information directly from server memory which is a much faster proposition instead of database connection and running query.

The right time to use Caching: 
A good caching strategy identifies the most frequently used pieces of data that are the most time consuming to create, and stores them.
  1. cache data (or web pages) that are expensive--> which uses database or file connection.
  2. cache data (or web pages) that are used frequently 
Caching types in ASP.Net
  1. Output caching-->it stores a copy of the final rendered HTML page that is sent to the client, so when client require the same page, the page isn't executed again and send directly to client.  
  • fragment caching --> instead of caching the HTML for the whole page, it allows you to cache the HTML for a portion of it (like caching user control of certain page)
      2. Data Caching --> carried out manually in your code, store important pieces of information that are time consuming 

  • Data source caching --> caching that's built into the data source controls including the SqlDataSource, ObjectDataSource and XmlDataSource. you simply configure the properties and the data source control manages the caching storage and retrieval. 
BUT NOTE THAT:
Using data caching is conceptually the same as using application state but it is much more server friendly because items will be removed from the cache automatically when it grows too large and performance could be affected.


**TRY Output Caching...
you have two alternatives to carry out output caching 


1. insert outputcache directive at the top to .aspx page 
%@ OutputCache Duration="20" VaryByParam="None" %

* Duration paramter: it is duration which asp.net will cache the page in seconds

2. caching page at client side by insert the outputcache directive with location attribute location = "client"
%@ OutputCache Duration="20" VaryByParam="None" Location="Client" %


*browser caches the page at client side, and client can get it by retype the same link or   back to the page but if the client refresh the page, the page will be abandoned and the                    page will be reqested again from the server.  
*can be useful technique if your cached page uses some sort of personalized data. even   though each user is in a separate session, the page will be created only one and reused for all         clients ensuring that most will receive the wrong greeting.

if the page is receiving information from another page through the query string

*VaryByParam="None" --> tells ASP.Net that ou need to store only one copy of the cached    page which is suitable for al scenarios

*VaryByParam="*" --> to indicate that the page uses the query string and to instruct   ASP.Net to cache separate copies of the page for different query string arguments (i.e.           ASP.Net will examine the query string. if the string matches a previous request and a        cached copy of that page exists, it will be reused)

*VaryByParam="ProductID" && VaryByParam="ProductID;CurrencyType" --> ASP.Net   will examine the query string, looking for the ProductID parameter. Requests with         different ProductID parameters wil be cached separatelym but all other parameters will be    ignored.

i will working on my next blogs to complete full image of ASP.Net Caching methdology to get better web applications performance... any feedback will be welcome......... :D 

Saturday, May 23, 2009

Look at Difference between XmlDocument and XmlDataDocument

The DataSet class in ADO.NET provides the developer with a relational view of data. Using the DataSet, data are stored as tables, which allows for easy retrievals using SQL statements. However, there are times when you need a hierarchical representation of the data, allowing you to perform quick searches using, say, XPath queries. You may also need to transform a set of data into another format using XSLT. In such cases, the .NET framework provides you with the XmlDocument class for this purpose.

However, the DataSet and XmlDocument classes only allow one way of data representation--either you have a relational or hierarchical view, but not both. It is with this purpose that the XmlDataDocument class was designed. The XmlDataDocument class is derived from the XmlDocument class, providing a hierarchical view of data as well as a relational view by binding it to a DataSet. Best of all, it automatically synchronizes the data changes made by either one of the two views. XmlDataDocument provides the best of both worlds--it can manipulate the data using the familiarDataSet, as well as support the various services in the XML classes (such as DOM, XPath, and XSLT). In this case, I will show you how you how to use the XmlDataDocument class

XmlDataDocument Allows structured data to be stored, retrieved, and manipulated through a relational DataSetThis class extends XmlDocument. It enables you to load either relational data or XML data and manipulate that data using the World Wide Web Consortium (W3C) Document Object Model (DOM). The DOM presents data as a hierarchy of node objects. Because XmlDataDocument implements the IXPathNavigable interface, it can also be used as the source document for the XslTransform class.

XmlDataDocument has a close affiliation with the DataSet class, which provides a relational view of the loaded XML data. Any changes made to theXmlDataDocument are reflected in the DataSet and vice versa.
 
And Now let's go through the difference between XmlDocument and XmlDataDocument 

  • XML Document
  1. The XmlDocument, XmlNode and other classes implement the W3C Document Object Model Level 1 Core and the Core DOM Level 2 specifications. 
  2. The XmlDocument is an in-memory (cache) tree representation of an XML document. 
  3. There are different node types specializing from XmlNode to enable you to manipulate the XML document. 
  4. You can get faster, non-cached, forward-only stream access to XML using the XmlTextReader and XmlTextWriter classes
  • XML DataDocument
  1. The XmlDataDocument class provides an in memory cache for XML data. 
  2. The XmlDataDocument extends the XmlDocument class. XmlDataDocument can be used anywhere the XmlDocument class is used. 
  3. There is a close association between the XmlDataDocument and the DataSet classes. In fact, you can regard the XmlDataDocument as a DataSet-aware XmlDocument. 

Friday, May 15, 2009

Jump 1 into WFF, Let's Jump

In the business world, workflow is how an item is moved from one person to another through a process. That process is the business process, and it defines the steps necessary to complete a piece of work. Steps in the process can be required or optional. Let’s spot on the second two business workflow:

For Example, you might have a process that automatically updates a sales order as complete, and sends an e-mail notice to the customer and the sales person when a sales order is shipped.

Another Example, a business process for a vacation request might be that the employee must provide some information, such as the dates requested, to his or her supervisor. Then, the employee's supervisor must determine if the employee has vacation time to use, and if the date or dates requested are available for vacation. The supervisor must provide the date information to the human resources department. Finally, the human resources department verifies that all policies have been followed, and provides the information to accounting at the appropriate time so payroll adjustments can be made.

So in software planet, we try to build solution that fit the business requirements for our customers with different rules & conditions including variety of business workflows. Implementing workflows would require a lot of while loops and if branching but Microsoft introduces a new component in .Net 3.0 framework called workflow foundation (WFF)

Microsoft .Net 3.0 consists of the following component:
  • .Net Framework
  • Microsoft Windows Communication Foundation
  • Microsoft Windows Presentation Foundation
  • Microsoft Windows Workflow Foundation

But why we go for consuming time and effort to learn WFF, The biggest reason to create workflow, is that you're creating a model (like flowchart, UML diagram) but in WFF the model and workflow is the same thing. Finally, WF allows processes to change on the fly. You can change the process while instances of the process are running, and the instances will adhere to the new process.

In this series, we will jump into workflow foundation, and extend our skills to develop business solutions depending on WFF but note that workflow is not an application or a server product, and is included as a component of the .Net 3.0 framework. So once you develop workflow you can host it on any application according to your business requirements such as windows forms, windows services, ASP.Net, web services, console application, and SharePoint server.

You can build workflow by using markup or code or combination between markup and code

Before we start our jump I want to mention the difference between workflow foundation and BizTalk server is WFF is a platform for developing workflow within applications but BizTalk server is a server product targeted for business process automation.

There are two major types of workflows:
  1. Sequential workflows: used for well-defined, process workflows, Sequential workflow is a workflow whose steps are performed one right after the other, but might include branching. Steps in a Sequential workflow don't wait for an external entity to perform the next step.
  2. State Machine workflows: Organized as state machine diagrams, typically used for workflows with human interaction. A state-based workflow means that each step of the flow has criteria that must be met before the flow can continue to the next step. A state-based workflow waits on external entities to perform some action before moving to the next step.