Example #1
0
 public static void SetToWithDefault <TItem, TRhs, TKey>(
     this ICache <TItem, TKey> not,
     IReadOnlyCache <TRhs, TKey> rhs,
     IReadOnlyCache <TRhs, TKey>?def,
     Func <TRhs, TRhs?, TItem> converter)
     where TRhs : class
 {
     if (def == null)
     {
         not.SetTo(
             rhs.Items.Select((t) => converter(t, default)));
     }
     else
     {
         not.SetTo(
             rhs.Select((t) =>
         {
             TRhs?defVal;
             if (def.TryGetValue(t.Key, out var get))
             {
                 defVal = get;
             }
             else
             {
                 defVal = default;
             }
             return(converter(t.Value, defVal));
         }));
     }
 }
Example #2
0
 public async Task OneTimeSetUp()
 {
     _cache = await new ReadOnlyCacheBuilder <IPAddress, LatLon>("ip-lat-lng", new IpApiDataSource())
              .WithLocalCache(new MemoryCache <IPAddress, LatLon>())
              .WithLoggerFactory(new ConsoleLoggerFactory())
              .BuildAsync();
 }
Example #3
0
 public async Task OneTimeSetUp()
 {
     _cache = await new ReadOnlyCacheBuilder <TemplateData, string>("templates", new TemplateDataSource())
              .WithLocalCache(new MemoryCache <TemplateData, string>())
              .WithLoggerFactory(new ConsoleLoggerFactory())
              .BuildAsync();
 }
Example #4
0
 public static void RemapLinks <TMajorGetter>(this IReadOnlyCache <TMajorGetter, FormKey> cache, IReadOnlyDictionary <FormKey, FormKey> mapping)
     where TMajorGetter : class, IMajorRecordCommonGetter, IFormLinkContainer
 {
     foreach (var item in cache.Items)
     {
         item.RemapLinks(mapping);
     }
 }
        public InMemoryCacheIndex(IReadOnlyCache <TKey, TValue> cache, ICache <TIndex, TValue> index,
                                  Func <TValue, TIndex> keyProvider)
        {
            _index       = index;
            _keyProvider = keyProvider;

            _cache   = cache;
            _added   = _cache.Subscribe((IObserver <CacheItemAdded <TValue> >) this);
            _removed = _cache.Subscribe((IObserver <CacheItemRemoved <TValue> >) this);
            _updated = _cache.Subscribe((IObserver <CacheItemUpdated <TValue> >) this);
        }
Example #6
0
 public LocalGetBenchmark()
 {
     _concurrentDictionary = CreateConcurrentDictionary();
     _modernCache          = CreateModernCache();
     _cacheTower           = CreateCacheTower();
     _foundatio            = CreateFoundatio();
     _lazyCache            = CreateLazyCache();
     _fusionCache          = CreateFusionCache();
     _easyCache            = CreateEasyCache();
     _cacheManager         = CreateCacheManager();
 }
Example #7
0
 public static bool TryGetValue <TObject, TKey>(this IReadOnlyCache <TObject, TKey> cache, TKey key, [MaybeNullWhen(false)] out TObject value)
 {
     // ToDo
     // Improve to not double query
     if (cache.ContainsKey(key))
     {
         value = cache[key];
         return(true);
     }
     value = default;
     return(false);
 }
        public async Task OneTimeSetUp()
        {
            _docker       = new DockerClientConfiguration().CreateClient();
            _containerIds = await Task.WhenAll(
                RunContainerAsync(_docker, "redis", 6379),
                RunContainerAsync(_docker, "postgres", 5432, new[] { "POSTGRES_HOST_AUTH_METHOD=trust" })
                );

            var redis = await ConnectionMultiplexer.ConnectAsync("localhost,allowAdmin=true");

            string postgreSqlConnectionString = "Host=localhost;User ID=postgres";

            await InitializePostgreSql(postgreSqlConnectionString);

            _cache = await new ReadOnlyCacheBuilder <Guid, User>("test", new UserDataSource(postgreSqlConnectionString))
                     .WithLocalCache(new MemoryCache <Guid, User>())
                     .WithDistributedCache(new RedisAsyncCache(redis), new ProtobufKeyValueSerializer <Guid, User>())
                     .WithLoggerFactory(new ConsoleLoggerFactory())
                     .WithPreload(_ => Task.FromResult <IEnumerable <Guid> >(new Guid[] { new("c11f0067-ec91-4355-8c7e-1caf4c940136") }), null)
Example #9
0
    public static IEnumerable <KeyValuePair <K, R> > SelectAgainst <K, V, R>(
        this IReadOnlyCache <V, K> lhs,
        IReadOnlyCache <V, K> rhs,
        Func <K, V, V, R> selector,
        out bool equal)
    {
        var ret = new List <KeyValuePair <K, R> >();

        equal = lhs.Count == rhs.Count;
        foreach (var item in lhs)
        {
            if (!rhs.ContainsKey(item.Key))
            {
                equal = false;
                continue;
            }
            ret.Add(
                new KeyValuePair <K, R>(
                    item.Key,
                    selector(item.Key, item.Value, rhs[item.Key])));
        }
        return(ret);
    }
Example #10
0
 public ReadOnlyValue(IReadOnlyCache <int, T> cache)
 {
     _cache = cache;
 }
 public void MyTestInitialize()
 {
     _mockCacheable = new Mock <ICacheable <int, ITestObject> >();
     _cache         = new ReadOnlyPicnicCache <int, ITestObject>(x => x.Id, _mockCacheable.Object);
 }