forked from siteserver/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContentTagManager.cs
More file actions
77 lines (64 loc) · 2.27 KB
/
ContentTagManager.cs
File metadata and controls
77 lines (64 loc) · 2.27 KB
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
72
73
74
75
76
77
using System.Collections.Generic;
using System.Linq;
using SiteServer.CMS.Core;
using SiteServer.CMS.DataCache.Core;
using SiteServer.CMS.Model;
namespace SiteServer.CMS.DataCache
{
public static class ContentTagManager
{
private static class ContentTagManagerCache
{
private static readonly object LockObject = new object();
private static readonly string CacheKey = DataCacheManager.GetCacheKey(nameof(ContentTagManager));
public static void Clear()
{
DataCacheManager.Remove(CacheKey);
}
public static Dictionary<int, List<ContentTagInfo>> GetAllContentTags()
{
var retval = DataCacheManager.Get<Dictionary<int, List<ContentTagInfo>>>(CacheKey);
if (retval != null) return retval;
lock (LockObject)
{
retval = DataCacheManager.Get<Dictionary<int, List<ContentTagInfo>>>(CacheKey);
if (retval == null)
{
retval = DataProvider.ContentTagDao.GetAllContentTags();
DataCacheManager.Insert(CacheKey, retval);
}
}
return retval;
}
}
public static void ClearCache()
{
ContentTagManagerCache.Clear();
}
public static bool IsExists(int siteId, string groupName)
{
var list = GetContentTagInfoList(siteId);
return list.Any(group => group.TagName == groupName);
}
public static ContentTagInfo GetContentTagInfo(int siteId, string groupName)
{
var list = GetContentTagInfoList(siteId);
return list.FirstOrDefault(group => group.TagName == groupName);
}
public static List<string> GetTagNameList(int siteId)
{
var list = GetContentTagInfoList(siteId);
return list.Select(group => group.TagName).ToList();
}
public static List<ContentTagInfo> GetContentTagInfoList(int siteId)
{
List<ContentTagInfo> list = null;
var dict = ContentTagManagerCache.GetAllContentTags();
if (dict != null && dict.ContainsKey(siteId))
{
list = dict[siteId];
}
return list ?? new List<ContentTagInfo>();
}
}
}