public void GetAndPreserveAccrossGC() { int count = 0; var cache = new WeakCache <int, IntHolder>(10, key => new IntHolder() { Int = count++ }); var v1 = cache.Get(1); GC.Collect(); Assert.Equal(v1.Int, cache.Get(1).Int); }
public void WeakCache_Get_works() { WeakCache <string> wc = new WeakCache <string>(); var value = wc.Get("test", () => "12345"); Assert.AreEqual("12345", value); }
public void WeakCache_Set_works() { WeakCache <string> wc = new WeakCache <string>(); wc.Set("test", "123"); Assert.AreEqual("123", wc.Get("test", null)); }
protected override IEnumerable <string> GetPrimaryKeys(string name) { return(_pkCache.Get(name, () => { var d = _schema.Value.GetTableSchemaDictionary(name); return d.Where(x => x.Value.IsPrimaryKey).Select(x => x.Value.FieldName).ToArray(); })); }
public void WeakCache_callback_called_at_right_times() { bool called = false; WeakCache <object> wc = new WeakCache <object>(); Func <object> callback = () => { called = true; return(new object()); }; wc.Get("test", callback); Assert.IsTrue(called); called = false; wc.Get("test", callback); Assert.IsFalse(called); GC.Collect(); called = false; wc.Get("test", callback); Assert.IsTrue(called); }
/// <summary> /// Creates a state. /// </summary> /// <param name="controlMode">The control state of the machine</param> /// <param name="fieldValues">The values of each data field. This array is captured; the method /// assumes that the array passed as an argument will never be modified.</param> /// <param name="domainMap">A mapping of domain names to integers that represent the next available id.</param> /// <param name="modelName">name of the model</param> /// <param name="locationNames">names of locations</param> /// <returns>A state with the given control mode, field values and domain map.</returns> public static SimpleState CreateState(Term controlMode, Term[] fieldValues, Map <Symbol, int> domainMap, string modelName, ValueArray <string> locationNames ) { SimpleState newState = new SimpleState(controlMode, fieldValues, domainMap, modelName, locationNames); return(cache.Get(newState)); }
public void GetAndDoNotPreserveAccrossGC() { int count = 0; var cache = new WeakCache <int, IntHolder>(10, key => new IntHolder() { Int = count++ }); var v1Value = GetValue(cache); GC.Collect(); Assert.NotEqual(v1Value, cache.Get(1).Int); }
protected override bool OnCompleted(IObserver <IElement> sink) { foreach (var table in Source.GetTablesWithNames()) { int tableIndex = table.Item1; string tableName = table.Item2; var tableSchema = _schemaCache.Get(tableName, () => { return(Source.GetFieldsWithNames(tableIndex).ToDictionary(x => x.Item2, x => x.Item1)); }); int i = 0; foreach (var items in Source.GetAllRows(tableIndex)) { var element = new DataElement(tableName, (i++).ToString(), items, tableSchema); sink.OnNext(element); } } return(true); }
private static int GetValue(WeakCache <int, IntHolder> cache) { //Put this in its own method so that the implicit local reference does not save the weak reference from the GC return(cache.Get(1).Int); }
/// <summary> /// Gets the virtual method set of a particular type: the set of /// all virtual methods defined in the type itself or any of /// its (recursive) base types that are not (yet) implemented /// in the type. /// </summary> /// <param name="type">The type to query.</param> /// <returns>A set of virtual methods.</returns> public static IEnumerable <IMethod> GetVirtualMethodSet(this IType type) { return(virtualMethodSets.Get(type, BuildVirtualMethodSet)); }
public IDictionary <string, SchemaFieldItem> GetTableSchemaDictionary(string tableName) { return(_tableSchemaCache.Get(tableName.ToLower(), () => { return GetTableSchema(tableName).ToDictionary(x => x.FieldName); })); }
protected virtual object QueryValue(string sql, object value) { string key = String.Format("{0}${1}", sql, value); return(_valueCache.Get(key, () => _db.Value.ExecuteScalar(sql, value))); }
/// <summary> /// Create a pair state from two states /// </summary> public static PairState CreateState(IState first, IState second) { return(cache.Get(first, second)); }