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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:37:22+00:00 2026-06-11T09:37:22+00:00

I need to store a list of data in the cache. Sometimes I’ll need

  • 0

I need to store a list of data in the cache.

Sometimes I’ll need full list sometimes I’ll only need to query the results and return one item from the list.

Current logic for one item is this:

User result;
var cachedUsers = _cache.Get<List<User>>(Constants.Cache.UsersKey);
if( cachedUsers != null)
{
    result = cachedUsers.FirstOrDefault(u => u.UserID == userID);

    if (result != null)
        return result;
}

result = GetUserFromDb(userID);

if (cachedUsers != null)
{
    cachedUsers.Add(result);
    _cache.Store(StoreMode.Set, Constants.Cache.UsersKey, cachedUsers);
}

return result;

Can I access one element directly from the cache without loading full list of users? I’d also need to logic to add a user into the cache without loading full list and overwriting it.

EDIT: I have option to store items separate from the list, or write the cache from scratch with different approach.

What is the best way to implement this logic?

  • 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-11T09:37:23+00:00Added an answer on June 11, 2026 at 9:37 am

    The most granular action you can do is to retrieve a particular key. If you store a list of items under that key, you get the list. To get exactly one item, you’ll need to store an item per key.

    There are various strategies for this, however note that atomicity is at the key level so doing actions across multiple keys could result in race conditions.

    Personally, I would custom serialize your list (instead of relying on default .NET serialization) as this will be fairly quick. But this depends on how many times “sometimes” is when talking about updating individual keys or requesting individual keys. The common sense “store it as you will use it” will apply here.

    For the custom serialization, we use Protobuf-net and store the resulting byte[] into the cache manually – as in, the caches takes and gives a byte[] and we do the serialization manually.

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

Sidebar

Related Questions

We need to store a list of data we pull from another table that
I need an efficient data structure to store a list of integers. The amount
I need to store data in memory where I map one or more key
i'm having a ListView control like I need to store the data from this
I am a beginner in C++. I need to store list of addresses that
I have a need to store an ordered list of strings and am trying
I'm trying to store a List as a DynamoDB attribute but I need to
I have a list of users in local store that I need to update
I need store just 10 arrays in my app, which I can change from
I need to store some data that looks a little like this: xyz 123

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.