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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:42:42+00:00 2026-05-10T18:42:42+00:00

I am currently building a web site and I just implemented SqlCacheDependency using LinqToSQL

  • 0

I am currently building a web site and I just implemented SqlCacheDependency using LinqToSQL like so.

   public IQueryable<VictoryList> GetVictoryList()    {                 string cacheKey = HttpContext.Current.User.Identity.Name + 'victoryCacheKey';                 IQueryable<VictoryList> cachednews = (IQueryable<VictoryList>)HttpContext.Current.Cache.Get(cacheKey);                  if (cachednews == null)                 {                      var results = from v in _datacontext.ViewVictoryLists                                   orderby _datacontext.GetNewId()                                   select new VictoryList                                   {                                       MemberID = v.MemberID,                                       Username = v.Aspnetusername,                                       Location = v.Location,                                       DaimokuGoal = v.DaimokuGoal,                                       PreviewImageID = v.PreviewImageID,                                       TotalDaimoku = v.TotalDaimoku,                                       TotalDeterminations = v.TotalDeterminations,                                       DeterminationID = v.DeterminationID,                                       DeterminationName = v.DeterminationName                                   };                     SqlCacheDependency dependency =                      new SqlCacheDependency(_datacontext.GetCommand(results) as SqlCommand);                      HttpContext.Current.Cache.Add(cacheKey, results, dependency, DateTime.MaxValue,                                   TimeSpan.Zero, CacheItemPriority.Normal, null);                       return results.ToList().AsQueryable();                 }                 return cachednews;    } 

It appears to be working as things are noticbly faster especially on some complex queries, however while looking at things in SQLProfiler I still see the query run through, I’m using the CommandBroker mode of SqlCacheDependency. Should I still see the query even though the data is obviously coming from a cached object?

  • 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. 2026-05-10T18:42:42+00:00Added an answer on May 10, 2026 at 6:42 pm

    I think that the problem is that you are storing IQueryable’s in your cache, and then cachednews contains an IQueryable that hits the database.

    Try the following changes.

    public IQueryable<VictoryList> GetVictoryList() {             // ...             if (cachednews == null)             {                  var results = from // ...                 results = results.ToList().AsQueryable(); // force query execution                  SqlCacheDependency dependency = // ...;                 HttpContext.Current.Cache.Add(cacheKey,                      results, // now just the result are stored                     dependency,                      DateTime.MaxValue,                     TimeSpan.Zero,                      CacheItemPriority.Normal,                      null);                   return results;             }             return cachednews; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently building an internal web application used in a factory/warehouse type location.
I'm currently building a small web application that includes a fair amount of JavaScript.
We're currently building a system that abstracts all kinds of technical details about web
I am currently building an Excel 2007 Add-in using VSTO (latest version + sp1)
I'm currently building a project and I would like to make use of some
Hi I am currently learning .net and am building my first real website using
I am currently building a small website where the content of the main div
I'm currently building a Java app that could end up being run on many
I am currently building in Version 3.5 of the .Net framework and I have
We're currently building an application that executes a number of external tools. We often

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.