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

  • Home
  • SEARCH
  • 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 4531926
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:57:53+00:00 2026-05-21T13:57:53+00:00

I recently downloaded some samples to use with AppFabric caching. I noticed in the

  • 0

I recently downloaded some samples to use with AppFabric caching. I noticed in the sample they used a class with static methods instead of a singleton.

I was thinking of changing it to a singleton for the following reasons:

  1. lazy load
  2. Only one instance of cache… I can’t think of a reason why more than one instance is needed.

Am I way off target or right on the money?

Below is a class they included:

public class CacheUtil
{
  private static DataCacheFactory _factory = null;
  private static DataCache _cache = null;
  public static DataCache GetCache()
  {
      if (_cache != null)
          return _cache;

      //-------------------------
      // Configure Cache Client 
      //-------------------------

      //Define Array for 1 Cache Host
      List<DataCacheServerEndpoint> servers = 
          new List<DataCacheServerEndpoint>(1);

      //Specify Cache Host Details 
      //  Parameter 1 = host name
      //  Parameter 2 = cache port number
      servers.Add(new DataCacheServerEndpoint("localhost", 22233));

      //Create cache configuration
      DataCacheFactoryConfiguration configuration = 
          new DataCacheFactoryConfiguration();

      //Set the cache host(s)
      configuration.Servers = servers;

      //Set default properties for local cache (local cache disabled)
      configuration.LocalCacheProperties = 
          new DataCacheLocalCacheProperties();

      //Disable tracing to avoid informational/verbose messages on the web page
      DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off);

      //Pass configuration settings to cacheFactory constructor
      _factory = new DataCacheFactory(configuration);

      //Get reference to named cache called "default"
      _cache = _factory.GetCache("default");

    return _cache;
  }
  • 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-21T13:57:54+00:00Added an answer on May 21, 2026 at 1:57 pm

    Yes. It is easy to implement:

        public class CacheUtil
        {
            private static DataCacheFactory _factory = null;
            private static DataCache _cache = null;
    
            // This is the single instance of this class
            private static readonly CacheUtil instance = new CacheUtil();
    
            private CacheUtil()
            {
                _cache = GetCache();
            }        
    
            /// <summary>
            /// Provides the single reference point to access this class
            /// </summary>
            public static CacheUtil Instance
            {
                get { return instance; }
            }
    
            private static DataCache GetCache()
            {
                if (_cache != null)
                    return _cache;
    
                //-------------------------
                // Configure Cache Client 
                //-------------------------
    
                //Define Array for 1 Cache Host
                List<DataCacheServerEndpoint> servers =
                    new List<DataCacheServerEndpoint>(1);
    
                //Specify Cache Host Details 
                //  Parameter 1 = host name
                //  Parameter 2 = cache port number
                servers.Add(new DataCacheServerEndpoint("localhost", 22233));
    
                //Create cache configuration
                DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration { 
    Servers = servers, 
    
    LocalCacheProperties = new DataCacheLocalCacheProperties() };
    
                //Disable tracing to avoid informational/verbose messages on the web page
                DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off);
    
                //Pass configuration settings to cacheFactory constructor
                _factory = new DataCacheFactory(configuration);
    
                //Get reference to named cache called "default"
                _cache = _factory.GetCache("default");
    
                return _cache;
            }
            /// <summary>
            /// Gets the cache
            /// </summary>
            public DataCache Cache { get; private set; }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently downloaded Visual Studio 2010b2, and wanted to re-evaluate some of my questions
I recently downloaded ndepend and ran an analysis on an open source project I
I recently downloaded the source tarball for a GTK application that I'd like to
I recently downloaded PLT Scheme and DrScheme. When I open DrScheme, I am told
recently I downloaded this open source project and I am trying to compile it.
Recently I have been investigating the possibilities of caching in ASP.NET. I rolled my
Recently, I started changing some of our applications to support MS SQL Server as
I have recently written some complex ruby script that eventually fails with segfaults in
Recently, I was trying to prototype some jQuery-based menu into ASP.NET MVC. Just to
I recently downloaded linux source from http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.34.1.tar.bz2 . I came across the below paragraph

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.