缓存数据访问层结果

发布于 2024-08-02 18:19:54 字数 352 浏览 0 评论 0原文

我想在数据访问层进行一些缓存以帮助提高性能。我决定使用 HTTPContext 缓存,并在顶部有一个抽象层,这样我就可以在需要时切换进出其他缓存策略。

基本上,缓存应该是不同的,这意味着对于每个单独的方法,它将根据传入的值缓存不同的结果。

我的问题是,如果我想要“每个函数的缓存”并且系统根据传递到方法中的值确定是否访问数据库或缓存,我将如何执行此操作(即获取项目值或其他内容的哈希值 - 但必须有更好的方法)。

我知道我可以用横切关注点、EL 和缓存应用程序块来做一些事情,但这样做的开销比我想要的要多一点。我想做一些相当轻量级的事情并且我可以控制(即我可以传递一个参数,我可以检查哪个参数会绕过缓存 - 例如)

干杯安东尼

I want to do some caching at the data access layer to help boost performance. I have decided that I will use the HTTPContext cache, with an abstraction layer on top so i can switch in and out other caching strategies later on if needed.

Basically the cache should be variant, meaning that for each individual method it will cache a different result based on the values that are passed in.

My question is given that if I am wanting to have a "cache per function" and for the system to determine whether to hit the database or the cache based on the values that are being passed into the method, how would I go about doing this (i.e. taking a hash of the items values or something - but there must be a better way).

I know that I could do some stuff with cross cutting concerns and the EL and the Caching Application Block, but the overhead of that is a little more than I am looking for. I am wanting to do something fairly light weight and that I can control (i.e. i could pass in a parameter that I could check which would bypass the cache - for instance)

Cheers Anthony

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独自唱情﹋歌 2024-08-09 18:19:54

为此,我们使用企业库缓存应用程序块。 Entlib Cache 的工作方式类似于具有键和值的字典。

Entlib 缓存允许您创建多个命名缓存,在您的情况下,每个函数一个。

在每个缓存中,您可以使用参数作为键。然后,您可以执行以下操作:

  • 尝试根据键从缓存中获取值。
  • 如果 value 为 null,则缓存中缺少该值。
  • 因此,从数据库中获取值并将结果放入缓存中,以便下次可用。

We use Enterprise Library Caching Application Block for this. Entlib Cache works like a dictionary with a key and a value.

Entlib cache allows you to create several named caches, in your case it would be one per function.

Within each cache you can use the parameters as the key. You can then do it as follows:

  • Try to get value from cache based on key.
  • If value is null, it is missing from the cache.
  • Therefore, get value from database and place the result in the cache, so that it is available next time.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文