如何在ASP.NET中创建用户特定的缓存 [英] How to create user specific cache in ASP.NET
本文介绍了如何在ASP.NET中创建用户特定的缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我是asp.net概念的新手,我的要求是我希望在缓存的帮助下保持点击按钮的次数。对于不同的用户,它应该是不同的数量。
由于某些原因我无法使用会话变量。
我已经完成了简单的缓存,但这不是每个用户。
提前致谢。 :)
我尝试过:
Hi All,
I am new to asp.net concepts and my requirement is that i want to maintain a count of a button click with help of cache. that is it should be different count for different users.
Due to some reasons i can't use session variable.
I have done with simple cache but that is not per user.
Thanks in advance. :)
What I have tried:
int x = 1;
if (Cache["click_count"] == null)
{
Cache["click_count"] = 1;
}
else
{
Cache["click_count"] = x + 1;
x = (int)Cache["click_count"];
}
推荐答案
Call the Insert method, passing the key and value of the item to add.
The following code example adds a string under the name CacheItem2:
string[] dependencies = { "CacheItem2" };
Cache.Insert("CacheItem3", "Cached Item 3",
new System.Web.Caching.CacheDependency(null, dependencies));
这里您的案例中的密钥可以是用户ID
here the key in your case can be user id
这篇关于如何在ASP.NET中创建用户特定的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文