Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

ASP.NET State Management And Caching

By Exforsys | on August 30, 2005 |
ASP.NET 2.0

ASP.NET State Management And Caching

In this tutorial you will learn about Cache Dependency, SqlCache Dependency, New methods added to the CacheDependency Class and The process of writing the cache dependency file.

The performance of any web application is incumbent upon the amount of server side processing that is required. Web servers must handle individual requests or multiple requests, give quick response time and reduce the load on intermediate and backend data systems. Output caching is regarded as one of the means of reducing server workload. It allows ASP.NET to send its most recent copy of the page to the browser rather than rerunning the code, querying the database and reassembling the page for every request. Cache can be defined as a hashtable used to store frequently accessed data. The data stored is global to the application and is visible within each currently active session.

Application, session and cache have similar structure and API. However, Session is a block of memory set aside for each user while Cache manages globally accessible data. Application and Cache both share application scope but differ from each other in the kind of support they give to item dependencies. An object added to the cache can be configured with file based, key based, time based dependencies. If the associated key changes or the time period expires, the object gets automatically removed from the cache. When the object is removed an event is triggered and code can be written to run on that event and load an updated version to Cache.

Cache is a server based approach to preserving state in an ASP.NET application. The dependency mechanism is encapsulated in the CacheDependency class. This class can represent a single file or directory or an array of files and directories or even items logically related to a particular item and added to the cache. The dependency between a cached item and an external component the developer has to use a specific overload of the Insert method or the Add method.

CacheDependency dep=new CacheDependency(filename);
Cache.Insert(Key.Value.dep);

As stated earlier, if the specified file changes the cached item is automatically removed. This is because the file dependency is based on a file monitor object which is an instance of the FileSystemWatcher class. This is a class that is a managed wrapper around the Windows operating system feature—the file notification change functionality.

Cached items can be bound to other cached items in addition to file dependencies that are created. The item is subordinate to files and folders and arrays of keys. When either of them changes, the item will be invalidated and removed from the cache. If the developer wants to make the item dependent only on the Cache, the file name parameter will have to be set to Null. A number of different combinations with Cache items are supported in ASP.NET 2.0 to create effective dependencies between cached items and other elements. A Cache dependency can be made subordinate to other cache dependencies. This feature comes handy when changes have to be cascaded. Finally ASP.NET 2.0 supports customization of dependencies by making the CacheDependency class inheritable and providing a made to measure SqlCacheDependency cache that provides built in database dependency limited to SQL Server 7.0 and later.

Designing a Cache dependency file is not an easy task. Moreover, the developer must have a very good reason for writing one. Nevertheless, ASP.NET 2.0 makes the process of writing the cache dependency file as comfortable as possible.

1. The CacheDependency class is inheritable

2. The CacheDependency class picks up all of the base class functionality including constructors that accept array files or create dependencies for other cache items. The developer can review and retain only those constructors which are required by him.

3. The public constructor in the CacheDependency class reduces the amount of coding that needs to be done.

4. The base class handles all the dependencies and all issues relating to synchronization and disposal.

5. The start time feature also need not be framed from point zero. The capacity is inherited from the base class of constructors.

.

.

 

6. The number of new methods added to the CacheDependency Class make it extensible.

a. DependencyDispose is a protected method that releases the resources used by the class

b. GetUniqueID is a public method that retrieves a unique string identifier for the object

c. NotifyDependencyChanged is a protected method that informs the base class that the dependency .represented by an object has changed.

………………d. SetUtcLastModified is a protected method that marks the time when a dependency
………………changes.

………………e. HasChanged is a public Boolean read only property that indicates whether the
………………dependency has changed

………………f. UtcLastModified is a public read only property that gets the time from the
………………SetUtcLastModified.

7. The CacheDependency class has been designed to support only a limited set of well known dependencies. For instance the user cannot insert code to check whether a dependency condition has been meant.

………………a. The CacheDependency object internally sets up a file monitor object and receive a call
………………from it whenever the monitored object changes. This object is called a
………………FileSystemWatcher object .

………………b. It has an event handler and establishes a link between the CacheDependency object
………………and the Cache object and its items.

………………c. An event is fired whenever the monitored object changes.

8. In addition to creating a single dependency on an entry ASP.NET Cache also aggregates dependencies. For instance, a Cache entry can be made dependent both on a file and a SQL Server table.

………………a. Custom cache dependency objects inherit CacheDependency, so the array of
………………dependencies can be extremely wide.

………………b. The AggregateCacheDependency class is built as a custom cache dependency object
………………and inherits from the CacheDependency class.

9. The SqlCacheDependency class which inherits from CacheDependency class supports dependencies on SQL Server tables.

………………a. It implements features that are compatible with MSDE, SQL Server 7.0 and subsequent
………………versions.

………………b. The class works only when the tables on which dependencies have to be created are
………………enabled.

………………c. The SqlCacheDependency class has two constructors. The first takes the
………………SqlCommand object and the second accepts two strings—the database name and
………………the table name.

………………………..i. The SqlCacheDependency class sets up a dependency relationship with SQL
…………………………..Server 2005 known as command notification.

………………………..ii. Whenever there are changes in the tables involved the notification is sent to the
……………………………caller.

………………………..iii. The caller then handles the event and lets the parent know through the
……………………………. NotifyDependencyChanged.

………………d. Triggers and stored procedures will have to be created to handle any incoming
………………UPDATE, INSERT and DELETE statements.

………………e. This must be done before the application is published.

………………f. The command line tool aspnet_regsqlcache or the methods of
………………SqlCacheDependencyAdmin can be used to enable the database for notifications.

………………g. The database entry is to be bound to a connection string entry

………………h. The poll component then, accesses the newly created table to see whether other tables
………………have changed.

………………i. If one or more tables have to be monitored for changes they can be added to a list
………………programmatically by defining a trigger on the table that is sensitive to insert, updates and
………………deletions. The trigger can increment the value of the ChangeID column.

j. A key architectural component is the cache dependency manager object. This component accesses the table and reads the ChangeID field and informs the corresponding cache object if a change has occurred.

k. The cache dependency object is dependent on a helper cache key, whose name is defined in accordance with the table and the database. This helper cache entry is removed so that the original SqlCacheDependency object is invalidated.

« « ASP.NET Customizing the Session State Mechanism
ASP.NET Configuring Page-Level Caching » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 0 Followers
  • Popular
  • Recent
  • ASP.NET Working With Master Pages

    August 17, 2005 - 0 Comment
  • ASP.NET Creating Web Wizards

    September 16, 2005 - 0 Comment
  • ASP.NET Web Pages and Layout

    August 23, 2005 - 0 Comment
  • ASP.NET Data Source Object Model

    September 6, 2005 - 0 Comment
  • ASP.NET Creating Content for Master Page

    August 17, 2005 - 0 Comment
  • ASP.NET : Dynamic Image control

    September 16, 2005 - 0 Comment
  • ASP.NET – Adding Web Parts at Run Time

    August 22, 2005 - 0 Comment
  • Getting started with ASP.NET 2.0

    July 4, 2005 - 0 Comment
  • ASP.NET SqlDataSource Control

    September 6, 2005 - 0 Comment
  • ASP.NET Referencing Master Page Members

    August 17, 2005 - 0 Comment
  • Application Development in .NET

    November 21, 2007 - 0 Comment
  • ASP.NET Advanced Site Functionality

    September 16, 2005 - 0 Comment
  • ASP.NET : Dynamic Image control

    September 16, 2005 - 0 Comment
  • ASP.NET Creating Web Wizards

    September 16, 2005 - 0 Comment
  • Displaying Master-Detail Data on Separate Pages in ASP.NET

    September 16, 2005 - 0 Comment
  • ASP.NET Displaying Master-Detail Data on the Same Page

    September 13, 2005 - 0 Comment
  • ASP.NET DataBound Controls – Details View

    September 13, 2005 - 0 Comment
  • ASP.NET Using a Grid to Display Detail Information

    September 13, 2005 - 0 Comment
  • ASP.NET Adding Sorting and Paging in GridView

    September 10, 2005 - 0 Comment
  • ASP.NET GridView Filtering

    September 10, 2005 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • Application Development in .NET
  • ASP.NET Advanced Site Functionality
  • ASP.NET : Dynamic Image control
  • ASP.NET Creating Web Wizards
  • Displaying Master-Detail Data on Separate Pages in ASP.NET

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT