question

DangDKhanh-2637 avatar image
0 Votes"
DangDKhanh-2637 asked Viorel-1 answered

How to use cache in c++?

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++
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You need to implement your own class because there isn't one, for example

 class Cache
 {
     // TODO: Implement code...
 };
0 Votes 0 ·

1 Answer

Viorel-1 avatar image
1 Vote"
Viorel-1 answered

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Viorel,
Thanks for the answer.
I will invest more time on this.

0 Votes 0 ·