在内存中缓存查找表的最佳方法 [英] best way to cache lookup tables in memory

查看:90
本文介绍了在内存中缓存查找表的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几百个查询表,我想在内存中进行缓存. 我已经将它们拖放到Linq到sql实体映射器上.我想必须有一种比使用"HttpContext.Current.Cache"对象加载每个表更好的(通用)方式读取内存中的数据.
所有查找表均以"L_"开头,后跟内容类型的名称.

I have a few hundreds lookup tables that i would like to cache in memory. I have dragged and dropped them onto Linq to sql entity mapper.I imagine there must be a better(Genric) way to read the data in memory than loading each individual table using "HttpContext.Current.Cache" object.
All the lookup tables start with "L_" followed by the name of the type of the content.

任何评论将不胜感激.

最佳

推荐答案

10 GB的数据太多,无法缓存.

10 GB is too much of data to be cached.

使用.NET的(可能是System.Cache命名空间)自己的缓存.如果您曾经为移动应用程序等编写Web API,则可以重用缓存代码.

Use .NET's (probably System.Cache namespace) own cache. You will be able to reuse your cache code if you ever write Web API for mobile apps etc.

ASP.NET缓存使用WeakLinks,并且每当需要内存时,您偶尔使用的缓存项都将被删除.

ASP.NET cache uses WeakLinks and whenever memory is required, your occasionally used Cache Items will be removed.

如果要分布式缓存或需要持久化缓存,请使用Redis.

Use Redis if you want distributed cache or need persistence with your cache.

在存储过程中使用Sql Server自己的In内存表要比使用Entity Framework(而不是Redis)更好.

Using Sql Server's own In memory tables with Stored Procedures would be better than using Entity Framework (but not Redis).

这样编写您的服务层代码(此代码也可以在您的Web API中重用)

Write your service layer code like this (this code will be reusable with your Web APIs too)

private IList<TableName> GetAll()
{
    //find in cache and return  
    //load data if upper step doesn't find data in cache 
    // store data in cache for this specific lookup 
    // return data 
} 

我希望这会有所帮助.

I hope this will help.

这篇关于在内存中缓存查找表的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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