1 /* Copyright (C) 2004 - 2009 Versant Inc. http://www.db4o.com */ 2 3 using System.Collections; 4 using Db4objects.Db4o.Foundation; 5 using Db4objects.Db4o.Internal.Caching; 6 7 namespace Db4objects.Db4o.Internal.Caching 8 { 9 /// <exclude></exclude> 10 public class CacheStatistics : ICache4 11 { 12 private readonly ICache4 _delegate; 13 14 private int _calls; 15 16 private int _misses; 17 CacheStatistics(ICache4 delegate_)18 public CacheStatistics(ICache4 delegate_) 19 { 20 _delegate = delegate_; 21 } 22 Produce(object key, IFunction4 producer, IProcedure4 onDiscard )23 public virtual object Produce(object key, IFunction4 producer, IProcedure4 onDiscard 24 ) 25 { 26 _calls++; 27 IFunction4 delegateProducer = new _IFunction4_26(this, producer); 28 return _delegate.Produce(key, delegateProducer, onDiscard); 29 } 30 31 private sealed class _IFunction4_26 : IFunction4 32 { _IFunction4_26(CacheStatistics _enclosing, IFunction4 producer)33 public _IFunction4_26(CacheStatistics _enclosing, IFunction4 producer) 34 { 35 this._enclosing = _enclosing; 36 this.producer = producer; 37 } 38 Apply(object arg)39 public object Apply(object arg) 40 { 41 this._enclosing._misses++; 42 return producer.Apply(arg); 43 } 44 45 private readonly CacheStatistics _enclosing; 46 47 private readonly IFunction4 producer; 48 } 49 GetEnumerator()50 public virtual IEnumerator GetEnumerator() 51 { 52 return _delegate.GetEnumerator(); 53 } 54 Calls()55 public virtual int Calls() 56 { 57 return _calls; 58 } 59 Misses()60 public virtual int Misses() 61 { 62 return _misses; 63 } 64 ToString()65 public override string ToString() 66 { 67 return "Cache statistics Calls:" + _calls + " Misses:" + _misses; 68 } 69 } 70 } 71