I need a function like this:
AddToList(txtName, timeExpire);
It looks like self-descriptive, the item will automatically expire and removed
Just a quick example for the answer Will gave
Add reference to System.Runtime.Caching
MemoryCache cache = new MemoryCache("CacheName");
cache.Add(key, value, new CacheItemPolicy()
{ AbsoluteExpiration = DateTime.UtcNow.AddSeconds(20) });
You can then check if something is still in the cache by going
if (cache.Contains(key))
And if you want your cache to have a low time limit then you will need to change the refresh time of the cache with a nice little hack.
MemoryCache AbsoluteExpiration acting strange