请问"每个请求&QUOT会议;模式走高速缓存的优势在哪里? (QUOT;或QUOT;每节&QUOT会话每个请求&QUOT会议;) [英] Does the "session per request" pattern take advantage of the cache? ("Session per session" or "Session per request")

查看:108
本文介绍了请问"每个请求&QUOT会议;模式走高速缓存的优势在哪里? (QUOT;或QUOT;每节&QUOT会话每个请求&QUOT会议;)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从头开始构建新的应用程序这几天在Web应用程序。结果
(的技术是 Asp.Net ,我的ORM使用的实体框架。如果它事项)



我是不确定的,如果广泛使用的模式的 每个请求会话真是一个好。结果
在我看来,该模式的优点是高速缓存不增加,直到数据库会话crash\\ \\是太大,因此效率低下。



但不是每个请求一个新的会话太多了?这意味着每个服务器调用重置缓存,像自动完成有一个全新的缓存,甚至简单的Ajax请求,实际上是每次击键缓存复位。



的几率你会查询同一对象的实体行中的一个要求是很小的。



不是每个会话的会话是一个更好的模式?它既有优点意思




  1. 缓存不会永远增长。

  2. 缓存实际上可以使用...



所以... 为什么的每个请求会话的是如此广泛的应用和的每个会话的会话的不






澄清:<? / p>


  1. 当我写ORM会话它同时适用于 NHibernate的会议的EntityFramework的的DbContext

  2. 我的意思冲提交-的SaveChanges对每个请求的session\dbcontext的。


解决方案

对于我来说,这一切关于通过限制工作单位一个请求提供一致性。我不知道如何当事情出错每个会话的会话会工作。



例如,你会怎么做,如果多个请求已处理,然后你会得到一个在提交乐观并发异常?你可以有在这一点上几个合并冲突。



所以,每个请求一个会话只是限制了你的矛盾曝光,使工作单位的要求范围。


I build a new application from scratch this days in a web application.
(The technologies are Asp.Net and the ORM I'm using is Entity Framework. if it matters)

I'm uncertain if the widely used pattern session per request is really a good one.
As I see it, the advantage of the pattern is that the cache isn't increases until the database session crash\ being too big and thus inefficient.

But isn't a new session for every request is too much? It means every server call reset the cache, even simple ajax request like auto-complete has a brand new cache, in fact for every key stroke the cache resets.

The chances you will query the same object-entity-row in one request is small.

Isn't Session per session is a better pattern? it has both the advantages meaning

  1. The cache won't grow for ever.
  2. The cache can actually be used...

So... Why is session per request is so widely used and session per session is not?


Clarifications:

  1. When I wrote ORM session it applies both to NHibernate's session and EntityFramework's DbContext.
  2. I do mean to flush-commit-SaveChanges of the session\dbcontext on each request.

解决方案

For me, it all about providing consistency by constraining a unit of work to a single request. I'm not sure how a session per session would work when things go wrong.

For example, what would you do if several requests have been handled and then you get an optimistic concurrency exception on the commit? you could have several merge conflicts at that point.

So a session per request just limits your conflict exposure and makes unit of work on the request scope.

这篇关于请问&QUOT;每个请求&QUOT会议;模式走高速缓存的优势在哪里? (QUOT;或QUOT;每节&QUOT会话每个请求&QUOT会议;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆