17 using System.Collections;
18 using System.Collections.Generic;
20 namespace erminas.SmartAPI.Utils.CachedCollections
22 public class CachedList<T> : ICachedList<T> where T : class
24 private bool _isCachingEnabled;
26 public CachedList(Func<List<T>> retrieveFunc,
Caching caching)
28 RetrieveFunc = retrieveFunc;
29 _isCachingEnabled = caching ==
Caching.Enabled;
34 _isCachingEnabled = caching ==
Caching.Enabled;
46 public T GetByPosition(
int pos)
52 public IEnumerator<T> GetEnumerator()
55 return List.GetEnumerator();
58 public virtual void InvalidateCache()
63 public virtual bool IsCachingEnabled
65 get {
return _isCachingEnabled; }
66 set { _isCachingEnabled = value; }
78 public ICachedList<T> Refreshed()
84 public void WaitFor(Predicate<ICachedList<T>> predicate, TimeSpan wait, TimeSpan retryPeriod)
86 Wait.For(() => predicate(Refreshed()), wait, retryPeriod);
89 protected void EnsureListIsLoaded()
91 if (IsCachingEnabled && List != null)
96 List = RetrieveFunc();
99 protected virtual List<T> List {
get;
set; }
100 protected Func<List<T>> RetrieveFunc {
private get;
set; }
102 IEnumerator IEnumerable.GetEnumerator()
104 EnsureListIsLoaded();
105 return List.GetEnumerator();