Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3796188
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:11:52+00:00 2026-05-19T13:11:52+00:00

I am currently researching the integration of AppFabirc caching into my .net c# application

  • 0

I am currently researching the integration of AppFabirc caching into my .net c# application and looking for some code examples of such. Are there any open source or code samples available off AppFabric caching available that I can look at?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:11:53+00:00Added an answer on May 19, 2026 at 1:11 pm

    Cache Operations
    The first object to create when dealing with AppFabric caching is a DataCacheFactory. This can be created either with hard-coded configuration data that tells the factory how to contact the cache server, or with no configuration in which case it reads the configuration from your web.config/app.config file. My recommendation is that you keep your config information in your .config file, otherwise when you want to change something in your cache setup, you’ll need to re-compile and re-distribute your application. The important thing to remember about the DataCacheFactory is it is expensive to create – you definitely don’t want to create one of these for every cache operation. Consider using the Singleton pattern – see this question for more details.

    // Create a factory reading the config info from the .config file
    DataCacheFactory factory = new DataCacheFactory();
    

    The main interface to a cache is through the Cache object. A Cache is obtained from the DataCacheFactory’s GetCache method, passing in the name of the cache:

    DataCache myCache = factory.GetCache("myCache");
    

    Adding An Item to the Cache
    Each item in a cache has a key, which is a string. The key must be unique to the cache – if you pass in a key that already exists you’ll get an exception. The item to be cached must be serialisable so AppFabric can internally pass it around the servers in the cache. At the most basic level, items are added to the cache using the Add method.

    object myCachedItem = new Object();
    string myCachedItemKey = "MyCacheKey";
    myCache.Add(myCachedItemKey, myCachedItem);
    

    Removing an Item from the Cache

    myCache.Remove(myCachedItemKey);
    

    Simple as.

    Getting an Item From the Cache
    When getting an item from the cache, we use the cache-aside pattern. This means we look in the cache to see if the desired item is there (using the key). If the item is in the cache, we take the cached item (potentially casting it to a different type); otherwise we take steps to get the item from scratch e.g. reading from a database, and then cache it so it is there for us next time.

    object cachedObject;
    string myImportantDataKey = "MyImportantDataTable";
    DataTable myImportantData;
    
    // This is an object because everything is returned from the cache as an object
    cachedObject = myCache.Get(myImportantDataKey);
    // Check to see if we got something from the cache
    if (cachedObject == null)
    {
        // The requested item wasn't in the cache - a cache miss
        // Go get the data from the db
        myImportantData = getMyImportantDataFromMyDatabase();
    
        // Add the item to the cache so we've got it for next time
        myCache.Add(myImportantDataKey, myImportantData);
    }
    else
    {
        // We have the cached object so cast it to a DataTable
        myImportantData = (DataTable)cachedObject;
    }
    

    Updating an Item in the Cache

    // Put can be used to update an existing item in the cache
    // If the item does not exist then it functions like Add
    myCache.Put(myImportantDataKey, myUpdatedImportantData);
    

    That’s the basic CRUD operations, but there’s plenty more that you can get into for dealing with concurrency!


    The Windows Server AppFabric Training Kit can be downloaded here, it has a section on
    caching. Keep following the appfabric tag here as I’m sure over time there’ll be many more code samples solving problems for people.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im currently using a UITableView like any other, and I am researching into the
I'm in the process of researching into various NoSQL technologies and currently looking into
I am currently researching the best methods to integrate i18n into projects. There's several
I'm currently researching SQL Server 2008 as a business intelligence solution, and currently looking
I'm currently researching into Tapestry for my company and trying to decide if I
I'm researching the prospect of incorporating a blog into my site. Currently, my site
Im currently researching how to port the Data Access Layer of an existing .NET
I'm currently researching a way to produce non-photorealistic rendering in webgl. The best looking
I am currently researching the best practises (at a reasonably high level) for application
Currently I'm researching the best design pattern to implement for a windows form application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.