码迷,mamicode.com
首页 > 其他好文 > 详细

ABP缓存示例

时间:2018-01-24 15:33:08      阅读:1152      评论:0      收藏:0      [点我收藏+]

标签:取数   save   读取数据   inpu   sort   inf   osb   property   div   

private readonly ICacheManager _cacheManager;

public ProgrammeManage(ICacheManager cacheManager)
{
    _cacheManager = cacheManager;
}

/// <summary>
/// 定时任务:更新缓存(仅查询今年的投票结果、按照节目顺序排序)
/// </summary>
/// <returns></returns>
public async Task SaveVoteResult()
{
    GetAllProgrammeInfosByYearOutput result = GetVoteResult(DateTime.Now.Year).Result;
    await _cacheManager.GetCache("GetAllProgrammeInfosByYearOutput")
        .SetAsync("GetAllProgrammeInfosByYearOutput", result);
}

/// <summary>
/// 查询缓存
/// </summary>
/// <param name="inputYear"></param>
/// <param name="sortProperty"></param>
/// <returns></returns>
public async Task<GetAllProgrammeInfosByYearOutput> GetVoteResult(long inputYear,string sortProperty)
{
    var cache = _cacheManager
        .GetCache("GetAllProgrammeInfosByYearOutput");
    long year = inputYear == 0 ? DateTime.Now.Year : inputYear;
    //先尝试读取缓存,缓存没有则读取数据库
    var result =await cache.GetAsync("GetAllProgrammeInfosByYearOutput", async ()=> { return await GetVoteResult(year); }) as GetAllProgrammeInfosByYearOutput;
    return result;
}

ABP缓存示例

标签:取数   save   读取数据   inpu   sort   inf   osb   property   div   

原文地址:https://www.cnblogs.com/Lulus/p/8341459.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!