将可枚举或通用列表存储到MemoryCache中

时间:2018-09-29 17:44:58

标签: c# asp.net-core asp.net-core-mvc asp.net-core-2.0 memorycache

如何将Option Explicit Public Sub GetInfo() Dim IE As New InternetExplorer Application.ScreenUpdating = False With IE .Visible = True .navigate "http://www.bursamalaysia.com/market/listed-companies/company-announcements/#/?category=SH&sub_category=all&alphabetical=All" While .Busy Or .readyState < 4: DoEvents: Wend Dim links As Object, i As Long Set links = .document.querySelectorAll("#bm_ajax_container [href^='/market/listed-companies/company-announcements/']") For i = 0 To links.Length - 1 With ThisWorkbook.Worksheets("Sheet1") .Cells(i + 1, 1) = links.item(i) End With Next i .Quit End With Application.ScreenUpdating = True End Sub Enumerable存储到List中?我刚开始编程,并试图从这里的文章中了解:

会是这个吗?

MemoryCache

Memory Caching

我的代码:

IMemoryCache _cache;
var testdata = productcategoryrepository.GetAllProductCategory();
_cache.Set("Teststore", testdata);

1 个答案:

答案 0 :(得分:0)

这似乎可行:

public class HomeController : Controller
{
    private readonly IMemoryCache _cache;

    public HomeController(IMemoryCache cache)
    {
        _cache = cache;
    }
    public IActionResult Index()
    {
        var testdata = productcategoryrepository.GetAllProductCategory();
        _cache.Set("Teststore", testdata);

        return View();
    }
}