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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:01:49+00:00 2026-05-21T20:01:49+00:00

I have a function called on every single page: /// <summary> /// Gets the

  • 0

I have a function called on every single page:

/// <summary>
/// Gets the date of the latest blog entry
/// </summary>
public static DateTime GetNewestBlogDate()
{
    DateTime ReturnDate = DateTime.Now.AddDays(30);
    using (var db = new DataClassesDataContext())
    {
        var q = (from d in db.tblBlogEntries orderby d.date descending select new {d.date}).FirstOrDefault();
        if (q != null)
            ReturnDate = q.date;
    }
    return ReturnDate;
}

It works like this website, it gets the latest blog entry date and if it’s greater than the users cookie value it displays a new icon next to the blog link.

It seems rather wasteful to keep calling this function per page request, called 1:1 on the number of page requests you have. Say you have 30,000 page views per day, that’s 1,250 database queries per hour.

Is there any way I can cache this results, and have it expire say every hour?

I’m aware it’s a bit of a micro optimisation, but given 10 or so similar functions per page it might add up to something worthwhile. You could denormalise it into a single table and return them all in one go, but I’d rather cache if possible as it’s easier to manage.

  • 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-21T20:01:49+00:00Added an answer on May 21, 2026 at 8:01 pm

    Since it’s not based on the user (the cookie is, but the query doesn’t seem to be) – you can just use the standard ASP.NET Cache.

    Just insert the result with an expiration of 1 hour. If you like, you can even use the callback to automatically refresh the cache.

    Assuming you’ve stored it into MS-SQL, you could even use a SqlCacheDependency to invalidate when new data is inserted. Or, if your inserting code is well-factored, you could manually invalidate the cache then.

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

Sidebar

Related Questions

I have table called page which represents every single page in my website. page_id
I have a class called User with static function loginRequired(), which returns false if
I have a function called FindSpecificRowValue that takes in a datatable and returns the
I have a function called: void initializeJSP(string Experiment) And in my MyJSP.h file I
I have a function that I use called sqlf(), it emulates prepared statements. For
I have a user defined function in SQL called getBuisnessDays it takes @startdate and
I have a javascript function that manipulates the DOM when it is called (adds
I have some jQuery code. I have called an Ajax function file, file.php, that
I have a function called save(), this function gathers up all the inputs on
Suppose I have a function in a single threaded program that looks like this

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.