RecommendCache.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections.Generic;
  3. using CB.Cache;
  4. using CB.Entity;
  5. namespace CB.Data
  6. {
  7. public partial class Caches
  8. {
  9. /// <summary>
  10. /// 页面推荐列表 热点推荐列表
  11. /// </summary>
  12. /// <returns></returns>
  13. public static IList<RecommendInfo> GetRecommendList()
  14. {
  15. var cache = CBCache.GetCacheService();
  16. IList<RecommendInfo> list = cache.GetObject(CacheKeys.RecommendList) as IList<RecommendInfo>;
  17. if (null == list)
  18. {
  19. list = RecommendsService.ToList();
  20. cache.AddObject(CacheKeys.RecommendList, list);
  21. }
  22. return list;
  23. }
  24. /// <summary>
  25. /// 获取推荐信息 热点推荐
  26. /// </summary>
  27. /// <param name="id"></param>
  28. /// <returns></returns>
  29. public static RecommendInfo GetRecommend(int id)
  30. {
  31. var list = GetRecommendList();
  32. if (null == list || 0 >= list.Count)
  33. return null;
  34. RecommendInfo entity = null;
  35. foreach (var item in list)
  36. {
  37. if (id == item.Id)
  38. { entity = item; break; }
  39. }
  40. return entity;
  41. }
  42. /// <summary>
  43. /// 获取推荐内容 热点内容
  44. /// </summary>
  45. /// <param name="id"></param>
  46. /// <returns></returns>
  47. public static string GetRecommendContent(int id)
  48. {
  49. var entity = GetRecommend(id);
  50. return null == entity ? "" : entity.Content;
  51. }
  52. }
  53. }