Example #1
0
        public LazyCache(Func <T> function)
        {
            beacon  = new Beacon();
            cell    = new Cell <T>();
            state   = LazyCacheState.SET;
            monitor = new Monitor(() =>
            {
                beacon.Register();
                switch (state)
                {
                case LazyCacheState.CLEAR:
                    state      = LazyCacheState.CACHED;
                    cell.Value = function();
                    break;

                case LazyCacheState.CACHED:
                    state = LazyCacheState.CLEAR;
                    return(() => cell.Value = default(T));
                }
                return(null);
            });
            state = LazyCacheState.CLEAR;
        }
Example #2
0
 public void Clear()
 {
     state      = LazyCacheState.CLEAR;
     cell.Value = default(T);
 }