File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed
src/BootstrapBlazor/Services Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -139,6 +139,40 @@ public DateTimeOffset GetStartTime()
139139 return ret ;
140140 }
141141
142+ /// <summary>
143+ /// 获得 缓存数量
144+ /// </summary>
145+ public long Count
146+ {
147+ get
148+ {
149+ var count = 0 ;
150+ if ( Cache is MemoryCache c )
151+ {
152+ count = c . Count ;
153+ }
154+ return count ;
155+ }
156+ }
157+
158+ #if NET9_0_OR_GREATER
159+ /// <summary>
160+ /// 获得 缓存键集合
161+ /// </summary>
162+ public IEnumerable < object > Keys
163+ {
164+ get
165+ {
166+ var keys = Enumerable . Empty < object > ( ) ;
167+ if ( Cache is MemoryCache c )
168+ {
169+ keys = c . Keys ;
170+ }
171+ return keys ;
172+ }
173+ }
174+ #endif
175+
142176 #region Count
143177 public static int ElementCount ( object ? value )
144178 {
Original file line number Diff line number Diff line change @@ -55,4 +55,16 @@ public interface ICacheManager
5555 /// </summary>
5656 /// <param name="key"></param>
5757 void Clear ( object ? key = null ) ;
58+
59+ /// <summary>
60+ /// 获得 缓存数量
61+ /// </summary>
62+ long Count { get ; }
63+
64+ #if NET9_0_OR_GREATER
65+ /// <summary>
66+ /// 获得 缓存键集合
67+ /// </summary>
68+ IEnumerable < object > Keys { get ; }
69+ #endif
5870}
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ public void GetStartTime_Ok()
2424 Cache . Clear ( "BootstrapBlazor_StartTime" ) ;
2525 Cache . SetStartTime ( ) ;
2626 Assert . True ( DateTime . Now > Cache . GetStartTime ( ) ) ;
27+
28+ Assert . Equal ( 1 , Cache . Count ) ;
29+ Assert . Single ( Cache . Keys ) ;
2730 }
2831
2932 [ Fact ]
You can’t perform that action at this time.
0 commit comments