forked from smartstore/SmartStoreNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIDbCache.cs
More file actions
130 lines (110 loc) · 3.78 KB
/
Copy pathIDbCache.cs
File metadata and controls
130 lines (110 loc) · 3.78 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using System.Collections.Generic;
using System.Linq;
namespace SmartStore.Data.Caching
{
/// <summary>
/// Interface to be implemented by cache implementations.
/// </summary>
public interface IDbCache
{
/// <summary>
/// Controls whether query caching is enabled or idle
/// </summary>
bool Enabled { get; set; }
/// <summary>
/// Tries to the get cached entry by key.
/// </summary>
/// <param name="key">The cache key.</param>
/// <param name="value">The retrieved value.</param>
/// <returns>A value of <c>true</c> if entry was found in the cache, <c>false</c> otherwise.</returns>
bool TryGet(string key, out object value);
/// <summary>
/// Adds the specified entry to the cache.
/// </summary>
/// <param name="key">The entry key.</param>
/// <param name="value">The entry value.</param>
/// <param name="dependentEntitySets">The list of dependent entity sets.</param>
/// <param name="duration">The absolute expiration.</param>
DbCacheEntry Put(string key, object value, IEnumerable<string> dependentEntitySets, TimeSpan? duration);
/// <summary>
/// Invalidates all cache entries which are dependent on any of the specified entity sets.
/// </summary>
/// <param name="entitySets">The entity sets.</param>
void InvalidateSets(IEnumerable<string> entitySets);
/// <summary>
/// Invalidates cache entry with a given key.
/// </summary>
/// <param name="key">The cache key.</param>
void InvalidateItem(string key);
/// <summary>
/// Deletes all items from static and request cache
/// </summary>
void Clear();
/// <summary>
/// Tries to the get cached entry by key from (HTTP) request scope
/// </summary>
/// <param name="key">The cache key.</param>
/// <param name="value">The retrieved value.</param>
/// <returns>A value of <c>true</c> if entry was found in the cache, <c>false</c> otherwise.</returns>
bool RequestTryGet(string key, out DbCacheEntry value);
/// <summary>
/// Adds the specified entry to the request scoped cache.
/// </summary>
/// <param name="key">The entry key.</param>
/// <param name="value">The entry value.</param>
/// <param name="dependentEntitySets">The list of dependent entity sets.</param>
DbCacheEntry RequestPut(string key, object value, string[] dependentEntitySets);
/// <summary>
/// Invalidates all request scoped cache entries which are dependent on any of the specified entity sets.
/// </summary>
/// <param name="entitySets">The entity sets.</param>
void RequestInvalidateSets(IEnumerable<string> entitySets);
/// <summary>
/// Invalidates request scoped cache entry with a given key.
/// </summary>
/// <param name="key">The cache key.</param>
void RequestInvalidateItem(string key);
}
public class NullDbCache : IDbCache
{
public bool Enabled
{
get;
set;
}
public bool TryGet(string key, out object value)
{
value = null;
return false;
}
public DbCacheEntry Put(string key, object value, IEnumerable<string> dependentEntitySets, TimeSpan? duration)
{
return new DbCacheEntry { Key = key, Value = value, CachedOnUtc = DateTime.UtcNow, EntitySets = dependentEntitySets.ToArray(), Duration = duration };
}
public void InvalidateSets(IEnumerable<string> entitySets)
{
}
public void InvalidateItem(string key)
{
}
public void Clear()
{
}
public bool RequestTryGet(string key, out DbCacheEntry value)
{
value = null;
return false;
}
public DbCacheEntry RequestPut(string key, object value, string[] dependentEntitySets)
{
return new DbCacheEntry { Key = key, Value = value, CachedOnUtc = DateTime.UtcNow, EntitySets = dependentEntitySets.ToArray() };
}
public void RequestInvalidateSets(IEnumerable<string> entitySets)
{
}
public void RequestInvalidateItem(string key)
{
}
}
}