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 7969699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:16:41+00:00 2026-06-04T07:16:41+00:00

I am implementing caching using MemoryCache (.net 4.0) for caching global data which will

  • 0

I am implementing caching using MemoryCache (.net 4.0) for caching global data which will be used by all users of my website.

My initial approach:
Store a KeyedCollection which would hold a collection of the Customer objects with a key to get a single object. This collection could have up to 250 such objects. Whenever the cache expires, I would rebuild the KeyedCollection and add it to the cache.

New approach
Now, I am thinking why not store each Customer object directly to the cache with the customerid as the look-up key. Therefore, MemoryCache.Default would have upto 250 such Customer objects versus a single KeyedCollection.
Benefits:

  1. More efficient since I will get the Customer object directly from
    the cache without having to perform another look-up on the Keyed
    Collection.
  2. I would add a new Customer object to the cache only when it is
    requested for the first time. Sort of lazy addition as opposed to
    pre-building the entire cache.

Any thoughts on using one versus the other in terms of performance and other factors?

  • 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-06-04T07:16:42+00:00Added an answer on June 4, 2026 at 7:16 am

    The solution will depend on how often you need to work on the objects as a collection.

    Reasons for storing as a collection:

    • Storing each object individually, if all 250 objects are always
      populated, take up more space, as each item in cache would have an
      associated CacheItemPolicy. This case is probably unlikely,
      however.
    • You would not have strongly typed extension methods made
      available by Linq on collections. (The extension methods are
      available, but MemoryCache items are exposed as KeyValuePair<string,
      object>
      ).

    Reasons for storing individually:

    • You are only or mostly going to be working one a single object at a time.
    • You want each object to be created and removed from cache based on its own frequency of usage, rather than that of a whole collection.

    So, compare your likely usage scenario, and choose accordingly. Chances are, unless you are writing lots of .Where, .Select, etc, calls or have reason to pass around the whole collection, then storing individually is going to be the better choice.

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

Sidebar

Related Questions

I am implementing caching for my website which is using Zend Framework. I look
I've been looking into implementing caching at Repository level using the .NET 4.0 Caching
I'm implementing a PHP script which will need some caching capabilities. I'm trying to
I am implementing a caching mechanism. I have written a HTTPModule which would intercept
Is the approach for implementing substitution caching in MVC 3 contained in this page
I have a wcf service that is secured using WIF. I'm implementing token caching
I'm implementing a content database for a C# Asp.Net MVC3 website in Sql Server.
I'm implementing a cache in a class library that i'm using in an asp.net
We are building an ASP.NET MVC application which will be deployed behind a hardware
I'm implementing some caching by using the nifty Rails.cache.fetch . However, in one particular

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.