简体   繁体   English

如果像会话一样使用数据缓存,它会有更好的性能

[英]If data caching used like a session would it have better performance

I am working on a maintenance of one asp.net application where I found pervious developers have implemented data caching as like a session, means they stored data in a cache for per session like this我正在维护一个 asp.net 应用程序,在该应用程序中,我发现以前的开发人员已经将数据缓存实现为像会话一样,这意味着他们将数据存储在每个会话的缓存中,就像这样

Public Function GetDataCache(ByVal dataCacheKey As String) As Object
    dataCacheKey = dataCacheKey & Convert.ToString(LoginSessionDO.UserID) 
    Return Cache(dataCacheKey)
End Function

In this application there are many screens where user can add multiple rows (data) in a grid temporary which actually store in cache for that particular current user only and finally press save button to save data in database.在这个应用程序中有许多屏幕,用户可以在临时网格中添加多行(数据),这些临时网格实际上仅存储在该特定当前用户的缓存中,最后按下保存按钮将数据保存在数据库中。

My question is if caching is used like a session!我的问题是缓存是否像会话一样使用! will it give any performance improvement?它会带来任何性能改进吗? actually I can change it in my dev.实际上我可以在我的开发中更改它。 environment to check performance but we cannot create load like prod in our environment and also without any surety I cannot change and deploy code in production.环境来检查性能,但我们不能在我们的环境中创建像 prod 这样的负载,而且在没有任何保证的情况下,我不能在生产中更改和部署代码。

Please suggest me请建议我

  1. Is caching is good the way its implemented?.缓存的实现方式是否良好?
  2. It's using like a session would it have better performance than session?它像会话一样使用它会比会话有更好的性能吗?

The cache will need to be cleared out, otherwise all items will remain until the app domain recycles.需要清除缓存,否则所有项目都将保留,直到应用程序域回收。 Session has a much shorter expiry and can be explicitly abandoned on log out, for example.例如,会话的到期时间要短得多,并且可以在注销时明确放弃。

This might be a scaling issue if your site grows.如果您的网站增长,这可能是一个扩展问题。 However, the shorter expiry time of the session might cause you issues with saving if it is no longer there when expected.但是,如果会话不再按预期存在,会话的较短到期时间可能会导致您无法保存。 A staging table in the db might be a better approach.数据库中的临时表可能是更好的方法。


An edit from several years after the initial answer.最初答案后几年的编辑。

In reality, it would be much preferable to store the added rows on the client side and then submit them all in one go.实际上,最好将添加的行存储在客户端,然后一次性提交。 Either of the server side options above run into issues if the app domain recycles in the middle of a session and both will cause you scaling issues on the server with enough users/data.如果应用程序域在会话中间回收,则上述任何一个服务器端选项都会遇到问题,并且两者都会导致您在具有足够用户/数据的服务器上出现扩展问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM