Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum length of cache keys in HttpRuntime.Cache object?

We are using HttpRuntime.Cache API in an ASP.NET to cache data retrieved from a database.

For this particular application, our database queries feature a LOT of parameters, so our cache keys look something like this:

table=table1;param1=somevalue1;param2=somevalue2;param3=somevalue3;param4=somevalue4;param5=somevalue5;param6=somevalue6... etc...

For some queries, we have so many parameters that the cache key is several hundred characters long.

My question: is there a limit to the length of these cache keys? Internally, it is using a dictionary, so theoretically the lookup time should be constant. However, I wonder if we have potential to run into some performance/memory problem.

like image 679
frankadelic Avatar asked Feb 24 '10 23:02

frankadelic


People also ask

Where is Httpruntime cache stored?

Cache is stored in web server memory.

What is in-memory cache in c#?

In-Memory Cache is used for when you want to implement cache in a single process. When the process dies, the cache dies with it. If you're running the same process on several servers, you will have a separate cache for each server. Persistent in-process Cache is when you back up your cache outside of process memory.

What is Caching in ASP net Core?

Caching makes a copy of data that can be returned much faster than from the source. Apps should be written and tested to never depend on cached data. ASP.NET Core supports several different caches. The simplest cache is based on the IMemoryCache. IMemoryCache represents a cache stored in the memory of the web server.


1 Answers

Internally, Dictionary uses the hash code of the key you give it. Effectively every key is stored as an integer.

You have nothing to worry about.

like image 174
BC. Avatar answered Oct 13 '22 12:10

BC.