How to use cache in c++?

DangDKhanh-2637 941 Reputation points
2021-08-20T22:15:45.5+00:00

Hi,
I have several objects.
Can I keep them in memory and access the data when I need as .NET memory cache?

cache.add("key", myclass);
cache["key"].value...

I am using vs2019, c++20.
Where should I start to achieve this?

Thanks you!

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,546 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 112.7K Reputation points
    2021-08-21T08:46:28.933+00:00

    If you enable the “Common Language Runtime Support” (C++/CLI), then you can use the WeakReference and MemoryCache classes.

    In case of normal C++, I think that the automatic expiration and eviction of objects is problematic — it will require a specific redesigned allocation functions (malloc, new, etc.).

    Maybe you can develop your own cache for your large objects.

    Check some attempts too: https://www.bing.com/search?q=c%2B%2B+cache.

    1 person found this answer helpful.