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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:23:27+00:00 2026-05-28T08:23:27+00:00

Can someone help me here? I have following code to store and revieve catch,

  • 0

Can someone help me here? I have following code to store and revieve catch, however, it doesn’t work. The cache expires in mins even I set it to 14 days in slidingExpiration. Thanks in advance!

public static List<ReplyDTO> VideoCommentList()
{
     List<ReplyDTO> replyList = new List<ReplyDTO>();
     if (HttpRuntime.Cache["videoComment"] == null)
     {
         HttpRuntime.Cache.Remove("videoComment");
         HttpRuntime.Cache.Insert("videoComment", replyList, null, Cache.NoAbsoluteExpiration, TimeSpan.FromDays(14));
     }
     else
     {
         replyList = (List<ReplyDTO>)HttpRuntime.Cache["videoComment"];
     }

     if (replyList.Count > 8)
     {
         replyList = replyList.OrderByDescending(x => x.DateCreated).Take(8).ToList();
     }
     else
     {
         replyList = replyList.OrderByDescending(x => x.DateCreated).ToList();
     }
     return replyList;
}

public static List<ReplyDTO> AddVideoComment(ReplyDTO replyDTO)
{
     List<ReplyDTO> replyList = new List<ReplyDTO>();
     replyList = VideoCommentList();
     replyList.Add(replyDTO);
     HttpRuntime.Cache.Insert("videoComment", replyList, null, Cache.NoAbsoluteExpiration, TimeSpan.FromDays(14));

     if (replyList.Count > 8)
     {
          replyList = replyList.OrderByDescending(x => x.DateCreated).Take(8).ToList();
     }
     else
     {
          replyList = replyList.OrderByDescending(x => x.DateCreated).ToList();
     }
     return replyList;
}
  • 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-28T08:23:28+00:00Added an answer on May 28, 2026 at 8:23 am

    ASP.net cache is in-memory, so if your IIS process or application pool recycles it will get clear. You can check following things which can cause recycling of process

    • If you modify web.config, IIS shutdown the old instance and slowly transfer the traffic to a new instance, in this process in-memory is recycled. How to check this: You can detect this situation by checking the AppDomain.IsFinalizingForUnload and logging that during the callback.
    • Application Pool Recycling: There is a configuration in IIS, according to which if IIS process is idle for a specified time, it recycles it. You can check this on server, and increase this time or disable the recycling altogether.
    • Every process has limitation on how much memory it can consume, if you are adding too many objects in memory, it will increase the memory consumption of IIS, and in critical time OS will recycle the process.

    EDIT

    In your program you are adding replyList item to cache and then doing .Take() operation. As replyList is reference object, if you modify it, it will get updated in the cache also. So if in your program, if you do replyList == null it will update the item in cache.

    So modify your code like this and try

    public static List<ReplyDTO> VideoCommentList()
    {
        List<ReplyDTO> replyList = new List<ReplyDTO>();
        if (HttpRuntime.Cache["videoComment"] == null)
        {
            //Call to .Remove is not required
            //HttpRuntime.Cache.Remove("videoComment");
            HttpRuntime.Cache.Insert("videoComment", replyList, null,
                             Cache.NoAbsoluteExpiration, TimeSpan.FromDays(14));
        }
        else
        {
            //No need to check count > 8, Take will handle it for you
            replyList = ((List<ReplyDTO>)HttpRuntime.Cache["videoComment"])
                            .OrderByDescending(x => x.DateCreated)
                            .Take(8).ToList();
        }
        return replyList;
    }
    
    public static List<ReplyDTO> AddVideoComment(ReplyDTO replyDTO)
    {
        //Read from cache
        List<ReplyDTO> replyList = ((List<ReplyDTO>)HttpRuntime.Cache["videoComment"]);
        if(replyList == null)
            replyList = VideoCommentList();
        replyList.Add(replyDTO);
        HttpRuntime.Cache.Insert("videoComment", replyList, null, Cache.NoAbsoluteExpiration, TimeSpan.FromDays(14));
    
        //Here you are creating a new list, and not referencing the one in the cache
        return replyList.OrderByDescending(x => x.DateCreated).Take(8).ToList();
    }
    

    IMPORTANT SUGGESTION

    If you want to check when and why your object is removed from the cache, you can take help of CacheItemRemovedCallback option on the insertion. Using this and CacheItemRemovedReason argument, you can log the reason of object removal from cache. Reasons

    1. Removed – Your code has removed the item from cache by calling Insert or Remove method.
    2. Expired – The item is removed from the cache because it expired.
    3. Underused – When system run low on memory, it freed up memory by removing item from the cache.
    4. DependencyChanged – The item is removed from the cache because the cache dependency associated with it changed. (In your case it is not valid)

    Hope this information helps you.

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

Sidebar

Related Questions

I'm really hoping someone can help me out here. I have a DataGrid in
Can someone help me convert the following code into code that instead has two
I have the following problem, maybe someone can help me (or explain, where my
I hope someone can help here, we're having an incredibly annoying time with Visual
An odd error here, perhaps someone can help track down source as it's attempting
I am out of ideas here, so I'm hoping someone can help. Here is
Can someone help me figure out the following make file? BINS=file1 file2 file3 all:
Can someone help explain the following: If I type: a=`ls -l` Then the output
Can someone help me with the getopt function? When I do the following in
Can someone help me correct the following error I keep getting when trying to

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.