Beispiel #1
0
        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);
        }
Beispiel #2
0
        public void WeakCache_Get_works()
        {
            WeakCache <string> wc = new WeakCache <string>();
            var value             = wc.Get("test", () => "12345");

            Assert.AreEqual("12345", value);
        }
Beispiel #3
0
        public void WeakCache_Set_works()
        {
            WeakCache <string> wc = new WeakCache <string>();

            wc.Set("test", "123");
            Assert.AreEqual("123", wc.Get("test", null));
        }
Beispiel #4
0
 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();
     }));
 }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        /// <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));
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
 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);
 }
Beispiel #9
0
 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));
 }
Beispiel #11
0
 public IDictionary <string, SchemaFieldItem> GetTableSchemaDictionary(string tableName)
 {
     return(_tableSchemaCache.Get(tableName.ToLower(), () => {
         return GetTableSchema(tableName).ToDictionary(x => x.FieldName);
     }));
 }
Beispiel #12
0
        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)));
        }
Beispiel #13
0
 /// <summary>
 /// Create a pair state from two states
 /// </summary>
 public static PairState CreateState(IState first, IState second)
 {
     return(cache.Get(first, second));
 }