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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:34:27+00:00 2026-06-01T16:34:27+00:00

I am pulling in data from a webservice and generally after I pull it

  • 0

I am pulling in data from a webservice and generally after I pull it in once the data will not change. This data would be referenced in different model objects. I am wondering what the best way to cache this in MVC would be. I was thinking a static Dictionary in the model class that would be using this data, but multiple threads could be reading and writing to it. Any suggestions?

  • 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-01T16:34:28+00:00Added an answer on June 1, 2026 at 4:34 pm

    I think your idea is pretty good (it’s what I’ve been doing so far anyway).
    The only gotcha is that you need to avoid concurrent access to your dictionary, so just make it private and have the accessor methods use a lock for both reading and writing (replace K and V with your own types):

    public class CacheClass {
        private static object DictLock = new Object();
        private static Dictionary<K, V> CachedData;
    
        public static V ReadDictionary(K key) {
             V temp;
             lock (DictLock) {
                  temp = CachedData[key];
             }
    
             return temp;
        }
        public static void SetDictionaryValue(K key, V value) {
             lock (DictLock) {
                 CachedData.Add(key, value);
             }
        }
    }  
    

    Other alternatives involve using a ConcurrentDictionary (.NET 4 or greater).
    This obviously does not deal with cache aging. But it seems to me like you are controlling this on your own.

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

Sidebar

Related Questions

Background: I'm building a small application that will be run daily, pulling data from
Anyone know of how they would go about pulling data from a Netezza backend
Accomplished pulling data from JSON, but having problems trying to pull additional information from
I found this wonderful example of pulling data from a Google spreadsheet in JSON:
I am working on an app that will be pulling data from a SQLite
In my PHP file, I use this line to pull data from my mySQL
I have a cakePHP application that is pulling data from two different databases, which
I am pulling data from one table, called analyzedCopy, and using it to over-rite
I am pulling data from Twitter's API and the return date is UTC in
I have an INSERT query that is pulling data from two tables and inserting

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.