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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:18:20+00:00 2026-05-12T23:18:20+00:00

I have the following, very interesting class … pubilc class Thing{ public Thing() {

  • 0

I have the following, very interesting class …

pubilc class Thing{

public Thing()
{
    DoSomethingThatTakesALongTime();
}

public boolean CheckSomething(string criteria)
{
    return  criteria == "something";
} }

In my ASP.Net MVC application, I need to make a call to CheckSomething very frequently.

As you can see, the constructor takes a long time to load.

What approaches can I use to cache the class? Keep in mind that I want to keep it testable … and I don’t know what that entails!!!!

Cheers,

ETFairfax

  • 1 1 Answer
  • 1 View
  • 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-12T23:18:21+00:00Added an answer on May 12, 2026 at 11:18 pm

    You could use the Factory Pattern to create it (Flyweight pattern to share memory)

    Create a Factory that returns an instance of the class. The factory would look like this

    if instance in cache

    • return cached instance

    if not

    • create instance
    • cache instance
    • return instance

    For cache you could use HttpContext Cache or Enterprise Library Cache.

    EDIT

    Interesting discussion below of which pattern this is.

    My understanding is as follows:

    • I ask something to create the object, that something is a factory, therefore factory pattern.
    • I try to reuse an object in memory, flyweight pattern. The python code in this example looks very much like my answer: http://en.wikipedia.org/wiki/Flyweight_pattern
    • But there is only a single instance of the object, therefore the singleton pattern
    • The cache where the object is stored is also a singleton
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following very simple Javascript-compatible regular expression: <script type=text/javascript id=(.+) src=([^]+)> I
I have the following issue using java 1.4 I try to display a very
Very simply put, I have the following code snippet: FILE* test = fopen(C:\\core.u, w);
The rails books and web pages I've been following have all stuck to very
I have a very simple Java RMI Server that looks like the following: import
I have following string String str = replace :) :) with some other string;
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I encountered an interesting thing today that I have never noticed before. It appears
I have been very intriuged by design patterns lately, and specifically following correct design

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.