ningshuxia
2022-12-12 e81ca048ef4e9345e904b74ffffd3e8413d18a7e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.Service
{
    /// <summary>
    /// AttachmentFile»º´æ¸¨ÖúÀà
    /// </summary>
    internal class AttachmentFileCacheHelper
    {
        private const string _contentKey = "AttachmentFileListKey";
 
        private static string GetCacheKey(long CorpID)
        {
            var contentKey = string.Format("{0}-{1}", _contentKey, CorpID);
            return CacheHelper.GetCacheKey(contentKey);
        }
 
        /// <summary>
        /// ÉèÖûº´æ
        /// </summary>
        public static void Set(long CorpID, List<Model.AttachmentFile> list, int Minites = 30, int RandomSeconds = 0)
        {
            var cacheKey = GetCacheKey(CorpID);
            MemoryCacheHelper.Set(cacheKey, list, Minites * 60 + RandomSeconds);
        }
 
        /// <summary>
        /// »ñÈ¡»º´æ
        /// </summary>
        public static List<Model.AttachmentFile> Get(long CorpID)
        {
            var cacheKey = GetCacheKey(CorpID);
            return MemoryCacheHelper.Get<List<Model.AttachmentFile>>(cacheKey);
        }
 
        /// <summary>
        /// »ñÈ¡ÉèÖûº´æ
        /// </summary>
        public static List<Model.AttachmentFile> GetSet(long CorpID, Func<List<Model.AttachmentFile>> func, int Minites = 30, int RandomSeconds = 0)
        {
            var cacheKey = GetCacheKey(CorpID);
            return MemoryCacheHelper.GetSet(cacheKey, func, Minites * 60 + RandomSeconds);
        }
 
        /// <summary>
        /// ÒƳý»º´æ
        /// </summary>
        public static void Remove(long CorpID)
        {
            var cacheKey = GetCacheKey(CorpID);
            MemoryCacheHelper.Remove(cacheKey);
        }
 
        /// <summary>
        /// È«²¿ÒƳý
        /// </summary>
        public static void RemoveAll()
        {
            MemoryCacheHelper.Remove((key) =>
            {
                return key.Contains(CacheHelper.GetCacheKey(_contentKey));
            });
        }
 
 
    }
}