ASP.NET
  Home arrow ASP.NET arrow Page 3 - Preventing Simultaneous Logons
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Preventing Simultaneous Logons
By: Vadivel Mohanakrishnan
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 23
    2004-04-07

    Table of Contents:
  • Preventing Simultaneous Logons
  • The Traditional Approach
  • Data Caching to Our Rescue
  • The Solution

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Preventing Simultaneous Logons - Data Caching to Our Rescue


    (Page 3 of 4 )

    Caching may be defined as the process of keeping information in memory that takes a relatively long time to fetch for quick access the next time it is needed. There are really only two differences between the Application and the Cache objects.

    • The Cache object is thread-safe unlike the Application object, i.e. one doesn’t need to explicitly lock or unlock the Cache collection before adding or removing an item. However, the objects in the Cache collections will still need to be thread-safe themselves.

    • Items in the Cache collection are automatically removed if they expire, if memory in the server becomes limited, or one of their dependent objects or files changes. This means one can freely use the cache without worrying about wasting valuable server memory, as ASP.NET will remove items as needed.

    Adding an Object to the Cache collection

    There are several ways to insert an item in the Cache collection. You can simply assign it to a key name (as you would with the Session or the Application Collection). But this approach is generally not recommended, as it wouldn’t allow you to control the amount of time the object will be retained in the Cache. A better way of inserting an item into the Cache collection is to use its insert method.

    A little on these parameters is in the table below:

    Cache.Insert Parameters

    Parameter Description
    KeyA string that assigns a name to this cached item in the collection.
    ItemThe object you want to cache.
     DependenciesA “CacheDependency” object that allows you to create a dependency for this item in the cache. If you don't want to create a dependent item - just specify “Nothing” for this parameter.
    AbsoluteExpirationA “DateTime” object representing the time at which the item will be removed from the cache.
    SlidingExpirationA “TimeSpan” object represents how long ASP.NET will wait between requests before removing a cached item.
    CacheItemPrioritySpecifies how important it is for the cache item to remain in the cache. It can have “AboveNormal”, “BelowNormal”,”Default”, “High”, “Low”, “Normal” or “NotRemovable” as its value.
    CacheItemRemovedCallbackThe callback delegate provides a means for you to create your own function that is automatically called when the item is removed from the cache.

    Usually we won't use all these parameters at once. For example, we cannot set both a sliding expiration and an absolute expiration policy at the same time. If we want to use an absolute expiration, set the slidingExpiration parameter to TimeSpan.Zero.

    Here is an example:


    Cache.Insert("testItem"testobjNothingDateTime.Now.AddMinutes(60), TimeSpan.Zero)

    Absolute expiration is best recommended in situations when you know the information in a given item can only be considered valid for a specific amount of time. On the other hand, sliding expiration is more useful when you know that a cached item will always remain valid but should still be allowed to expire if not being used.

    To set the slidingExpliration policy, set the absoluteExpiration parameter to DateTime.Max as shown below.


    Cache.Insert("testItem"testobjNothingDateTime.MaxValueTimeSpan.FromMinutes(10))

    More ASP.NET Articles
    More By Vadivel Mohanakrishnan


       · protected void Application_PreRequestHandlerExecute(object sender, EventArgs e) ...
     

    ASP.NET ARTICLES

    - More Advanced ASP.NET 3.5 Functions and Subr...
    - ASP.NET 3.5 Functions and Subroutines
    - Coding an IQ Test with Conditionally Driven ...
    - Developing Conditionally Driven Event Handle...
    - ASP.NET 3.5 Debugging Using Visual Web Devel...
    - Understanding Event Handlers in ASP.NET 3.5
    - Building a Web Form in ASP.NET and PHP: a Co...
    - Inserting Data into a Microsoft SQL 2008 Dat...
    - Creating an ASP.NET Dynamic Web Page Using M...
    - Retrieving Data from Microsoft SQL Server 20...
    - Building ASP.NET Web Forms to Use a MySQL Da...
    - Creating an ASP.NET Database using MS SQL 20...
    - Building an ASP.NET Website Using Include Ta...
    - Create ASP.NET Web Forms to Use a Microsoft ...
    - Editing Web Design Layout in Visual Web Deve...





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek