Ejemplo n.º 1
0
        void Load()
        {
            Dictionary <int, Item> _items = PersistentCache.TryLoad <Dictionary <int, Item> >();

            if (_items == null)
            {
                return;
            }
            foreach (var item in _items)
            {
                try
                {
                    Items[item.Key].IsBuy      = item.Value.IsBuy;
                    Items[item.Key].IsSelected = item.Value.IsSelected;
                }
                catch (KeyNotFoundException)
                {
                    Item _item = new Item()
                    {
                        ID = item.Key, IsBuy = item.Value.IsBuy, IsSelected = item.Value.IsSelected
                    };
                    Items.Add(item.Key, _item);
                }
                catch (Exception ex)
                {
                    Debug.LogWarning(ex);
                }
            }
        }
Ejemplo n.º 2
0
        public static IEnumerable <PGPIResponse> GetPGPIResponses(string id)
        {
            Tuple <string, string, double>[] cacheValue = PersistentCache.get(id);

            if (cacheValue != null)
            {
                return(ConvertTupleToList(cacheValue));
            }

            if (pgpi == null)
            {
                pgpi = new PGPI();
            }

            string[] allPGPI = pgpi.getAllPGPIShortDesc();

            List <KeyValuePair <string, double> > topN = getTopN(SenSim.SemanticSimilarity.CalcSimilarity(id, pgpi.getEmbeddings(), SenSim.DistanceMetric.Cosine), RESULTCOUNT).ToList();

            cacheValue = new Tuple <string, string, double> [topN.Count];
            for (int i = 0; i < cacheValue.Length; i++)
            {
                string prod = pgpi.getPGPIShortDesc(topN[i].Key);
                cacheValue[i] = new Tuple <string, string, double>(prod, topN[i].Key, topN[i].Value);
            }
            PersistentCache.put(id, cacheValue);

            return(ConvertTupleToList(cacheValue));
        }
Ejemplo n.º 3
0
 void Load()
 {
     Data = PersistentCache.TryLoad <GameData>();
     if (Data == null)
     {
         Debug.Log("Data load unsuccessful");
         Data = new GameData();
     }
     SetControll(Data.InputType);
 }
Ejemplo n.º 4
0
        public void Save()
        {
            Data.BallPositionX   = Ball.transform.position.x;
            Data.BallPositionY   = Ball.transform.position.y;
            Data.CameraPositionY = Camera.transform.position.y;
            Data.InputType       = inputController.GetComponent <InputControllerBase>().InputType;

            PersistentCache.Save(Data);
            Debug.Log("Saved");
        }
Ejemplo n.º 5
0
 public void Load()
 {
     Model = PersistentCache.TryLoad <StartSettings>("model");
     if (Model == null)
     {
         Model = new StartSettings();
     }
     GravityInputField.text  = Model.BallGravity.ToString();
     SpeedInputField.text    = Model.BallSpeed.ToString();
     CamStartSpeed.text      = Model.CamStartSpeed.ToString();
     CamSpeedMultiplier.text = Model.CamSpeedMultiplier.ToString();
     CamMaxSpeed.text        = Model.CamMaxSpeed.ToString();
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the actual image content of the tile as byte array
        /// </summary>
        public virtual byte[] GetTile(TileInfo tileInfo)
        {
            var bytes = PersistentCache.Find(tileInfo.Index);

            if (bytes != null)
            {
                return(bytes);
            }
            bytes = _fetchTile(_request.GetUri(tileInfo));
            if (bytes != null)
            {
                PersistentCache.Add(tileInfo.Index, bytes);
            }
            return(bytes);
        }
Ejemplo n.º 7
0
        public void NewCache_NullPath()
        {
            ICache cache;

            try
            {
#pragma warning disable CC0022 // Should dispose object
                cache = new PersistentCache(new PersistentCacheSettings {
                    CacheFile = null
                }, clock: Kernel.Get <IClock>());
#pragma warning restore CC0022 // Should dispose object
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOf <ArgumentException>(ex);
                Assert.True(ex.Message.Contains(ErrorMessages.NullOrEmptyCacheFile));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        ///   Learn how to use KVLite by examples.
        /// </summary>
        public static void Main()
        {
            // Some variables used in the examples.
            var examplePartition1 = "example partition 1";
            var examplePartition2 = "example partition 2";
            var exampleKey1       = "example key 1";
            var exampleKey2       = "example key 2";
            var simpleValue       = Math.PI;
            var complexValue      = new ComplexValue
            {
                Integer         = 21,
                NullableBoolean = null,
                String          = "Learning KVLite",
                Dictionary      = new Dictionary <short, ComplexValue>
                {
                    [1] = new ComplexValue {
                        NullableBoolean = true
                    },
                    [2] = new ComplexValue {
                        String = "Nested..."
                    }
                }
            };

            /*
             * KVLite stores its values inside a given partition and each value is linked to a key.
             * KVLite can contain more than one partition and each partition can contain more than one key.
             *
             * Therefore, values are stored according to this logical layout:
             *
             * [partition1] --> key1/value1
             *              --> key2/value2
             * [partition2] --> key1/value1
             *              --> key2/value2
             *              --> key3/value3
             *
             * A key is unique inside a partition, not inside all cache.
             * A partition, instead, is unique inside all cache.
             */

            // You can start using the default caches immediately. Let's try to store some values in
            // a way similar to the figure above, using the default persistent cache.
            ICache persistentCache = PersistentCache.DefaultInstance;

            persistentCache.AddTimed(examplePartition1, exampleKey1, simpleValue, persistentCache.Clock.GetCurrentInstant() + Duration.FromMinutes(5));
            persistentCache.AddTimed(examplePartition1, exampleKey2, simpleValue, persistentCache.Clock.GetCurrentInstant() + Duration.FromMinutes(10));
            persistentCache.AddTimed(examplePartition2, exampleKey1, complexValue, persistentCache.Clock.GetCurrentInstant() + Duration.FromMinutes(10));
            persistentCache.AddTimed(examplePartition2, exampleKey2, complexValue, persistentCache.Clock.GetCurrentInstant() + Duration.FromMinutes(5));
            PrettyPrint(persistentCache);

            // Otherwise, you can customize you own cache... Let's see how we can use a volatile
            // cache. Let's define the settings that we will use in new volatile caches.
            var volatileCacheSettings = new VolatileCacheSettings
            {
                CacheName      = "My In-Memory Cache", // The backend.
                StaticInterval = Duration.FromDays(10) // How long static values will last.
            };

            // Then the settings that we will use in new persistent caches.
            var persistentCacheSettings = new PersistentCacheSettings
            {
                CacheFile            = "CustomCache.sqlite", // The SQLite DB used as the backend for the cache.
                ChancesOfAutoCleanup = 0.5,                  // Chance of an automatic a cache cleanup being issued.
                StaticInterval       = Duration.FromDays(10) // How long static values will last.
            };

            // We create both a volatile and a persistent cache.
            var volatileCache = new VolatileCache(volatileCacheSettings);

            persistentCache = new PersistentCache(persistentCacheSettings);

            // Use the new volatile cache!
            volatileCache.AddStatic(examplePartition1, exampleKey1, Tuple.Create("Volatile!", 123));
            PrettyPrint(volatileCache);

            // Use the new persistent cache!
            persistentCache.AddStatic(examplePartition2, exampleKey2, Tuple.Create("Persistent!", 123));
            PrettyPrint(persistentCache);

            /*
             * An item can be added to the cache in three different ways.
             *
             * "Timed" values last until the specified date and time, or for a specified timespan.
             * Reading them will not extend their lifetime.
             *
             * "Sliding" values last for the specified lifetime, but, if read,
             * their lifetime will be extended by the timespan specified initially.
             *
             * "Static" values are a special form of "sliding" values.
             * They use a very long timespan, 30 days by default, and they can be used for seldom changed data.
             */

            // Let's clear the volatile cache and let's a value for each type.
            volatileCache.Clear();
            volatileCache.AddTimed(examplePartition1, exampleKey1, simpleValue, volatileCache.Clock.GetCurrentInstant() + Duration.FromMinutes(10));
            volatileCache.AddTimed(examplePartition1, exampleKey2, complexValue, Duration.FromMinutes(15));
            volatileCache.AddStatic(examplePartition2, exampleKey1, simpleValue);
            volatileCache.AddSliding(examplePartition2, exampleKey2, complexValue, Duration.FromMinutes(15));
            PrettyPrint(volatileCache);

            Console.Read();
        }
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Mongouri != null)
         {
             hashCode = hashCode * 59 + Mongouri.GetHashCode();
         }
         if (Db != null)
         {
             hashCode = hashCode * 59 + Db.GetHashCode();
         }
         if (SocketKeepAlive != null)
         {
             hashCode = hashCode * 59 + SocketKeepAlive.GetHashCode();
         }
         if (Cache != null)
         {
             hashCode = hashCode * 59 + Cache.GetHashCode();
         }
         if (NodeCachePercentage != null)
         {
             hashCode = hashCode * 59 + NodeCachePercentage.GetHashCode();
         }
         if (PrevDocCachePercentage != null)
         {
             hashCode = hashCode * 59 + PrevDocCachePercentage.GetHashCode();
         }
         if (ChildrenCachePercentage != null)
         {
             hashCode = hashCode * 59 + ChildrenCachePercentage.GetHashCode();
         }
         if (DiffCachePercentage != null)
         {
             hashCode = hashCode * 59 + DiffCachePercentage.GetHashCode();
         }
         if (CacheSegmentCount != null)
         {
             hashCode = hashCode * 59 + CacheSegmentCount.GetHashCode();
         }
         if (CacheStackMoveDistance != null)
         {
             hashCode = hashCode * 59 + CacheStackMoveDistance.GetHashCode();
         }
         if (BlobCacheSize != null)
         {
             hashCode = hashCode * 59 + BlobCacheSize.GetHashCode();
         }
         if (PersistentCache != null)
         {
             hashCode = hashCode * 59 + PersistentCache.GetHashCode();
         }
         if (JournalCache != null)
         {
             hashCode = hashCode * 59 + JournalCache.GetHashCode();
         }
         if (CustomBlobStore != null)
         {
             hashCode = hashCode * 59 + CustomBlobStore.GetHashCode();
         }
         if (JournalGCInterval != null)
         {
             hashCode = hashCode * 59 + JournalGCInterval.GetHashCode();
         }
         if (JournalGCMaxAge != null)
         {
             hashCode = hashCode * 59 + JournalGCMaxAge.GetHashCode();
         }
         if (PrefetchExternalChanges != null)
         {
             hashCode = hashCode * 59 + PrefetchExternalChanges.GetHashCode();
         }
         if (Role != null)
         {
             hashCode = hashCode * 59 + Role.GetHashCode();
         }
         if (VersionGcMaxAgeInSecs != null)
         {
             hashCode = hashCode * 59 + VersionGcMaxAgeInSecs.GetHashCode();
         }
         if (VersionGCExpression != null)
         {
             hashCode = hashCode * 59 + VersionGCExpression.GetHashCode();
         }
         if (VersionGCTimeLimitInSecs != null)
         {
             hashCode = hashCode * 59 + VersionGCTimeLimitInSecs.GetHashCode();
         }
         if (BlobGcMaxAgeInSecs != null)
         {
             hashCode = hashCode * 59 + BlobGcMaxAgeInSecs.GetHashCode();
         }
         if (BlobTrackSnapshotIntervalInSecs != null)
         {
             hashCode = hashCode * 59 + BlobTrackSnapshotIntervalInSecs.GetHashCode();
         }
         if (RepositoryHome != null)
         {
             hashCode = hashCode * 59 + RepositoryHome.GetHashCode();
         }
         if (MaxReplicationLagInSecs != null)
         {
             hashCode = hashCode * 59 + MaxReplicationLagInSecs.GetHashCode();
         }
         if (DocumentStoreType != null)
         {
             hashCode = hashCode * 59 + DocumentStoreType.GetHashCode();
         }
         if (BundlingDisabled != null)
         {
             hashCode = hashCode * 59 + BundlingDisabled.GetHashCode();
         }
         if (UpdateLimit != null)
         {
             hashCode = hashCode * 59 + UpdateLimit.GetHashCode();
         }
         if (PersistentCacheIncludes != null)
         {
             hashCode = hashCode * 59 + PersistentCacheIncludes.GetHashCode();
         }
         if (LeaseCheckMode != null)
         {
             hashCode = hashCode * 59 + LeaseCheckMode.GetHashCode();
         }
         return(hashCode);
     }
 }
        /// <summary>
        /// Returns true if OrgApacheJackrabbitOakPluginsDocumentDocumentNodeStoreServiceProperties instances are equal
        /// </summary>
        /// <param name="other">Instance of OrgApacheJackrabbitOakPluginsDocumentDocumentNodeStoreServiceProperties to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(OrgApacheJackrabbitOakPluginsDocumentDocumentNodeStoreServiceProperties other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Mongouri == other.Mongouri ||
                     Mongouri != null &&
                     Mongouri.Equals(other.Mongouri)
                     ) &&
                 (
                     Db == other.Db ||
                     Db != null &&
                     Db.Equals(other.Db)
                 ) &&
                 (
                     SocketKeepAlive == other.SocketKeepAlive ||
                     SocketKeepAlive != null &&
                     SocketKeepAlive.Equals(other.SocketKeepAlive)
                 ) &&
                 (
                     Cache == other.Cache ||
                     Cache != null &&
                     Cache.Equals(other.Cache)
                 ) &&
                 (
                     NodeCachePercentage == other.NodeCachePercentage ||
                     NodeCachePercentage != null &&
                     NodeCachePercentage.Equals(other.NodeCachePercentage)
                 ) &&
                 (
                     PrevDocCachePercentage == other.PrevDocCachePercentage ||
                     PrevDocCachePercentage != null &&
                     PrevDocCachePercentage.Equals(other.PrevDocCachePercentage)
                 ) &&
                 (
                     ChildrenCachePercentage == other.ChildrenCachePercentage ||
                     ChildrenCachePercentage != null &&
                     ChildrenCachePercentage.Equals(other.ChildrenCachePercentage)
                 ) &&
                 (
                     DiffCachePercentage == other.DiffCachePercentage ||
                     DiffCachePercentage != null &&
                     DiffCachePercentage.Equals(other.DiffCachePercentage)
                 ) &&
                 (
                     CacheSegmentCount == other.CacheSegmentCount ||
                     CacheSegmentCount != null &&
                     CacheSegmentCount.Equals(other.CacheSegmentCount)
                 ) &&
                 (
                     CacheStackMoveDistance == other.CacheStackMoveDistance ||
                     CacheStackMoveDistance != null &&
                     CacheStackMoveDistance.Equals(other.CacheStackMoveDistance)
                 ) &&
                 (
                     BlobCacheSize == other.BlobCacheSize ||
                     BlobCacheSize != null &&
                     BlobCacheSize.Equals(other.BlobCacheSize)
                 ) &&
                 (
                     PersistentCache == other.PersistentCache ||
                     PersistentCache != null &&
                     PersistentCache.Equals(other.PersistentCache)
                 ) &&
                 (
                     JournalCache == other.JournalCache ||
                     JournalCache != null &&
                     JournalCache.Equals(other.JournalCache)
                 ) &&
                 (
                     CustomBlobStore == other.CustomBlobStore ||
                     CustomBlobStore != null &&
                     CustomBlobStore.Equals(other.CustomBlobStore)
                 ) &&
                 (
                     JournalGCInterval == other.JournalGCInterval ||
                     JournalGCInterval != null &&
                     JournalGCInterval.Equals(other.JournalGCInterval)
                 ) &&
                 (
                     JournalGCMaxAge == other.JournalGCMaxAge ||
                     JournalGCMaxAge != null &&
                     JournalGCMaxAge.Equals(other.JournalGCMaxAge)
                 ) &&
                 (
                     PrefetchExternalChanges == other.PrefetchExternalChanges ||
                     PrefetchExternalChanges != null &&
                     PrefetchExternalChanges.Equals(other.PrefetchExternalChanges)
                 ) &&
                 (
                     Role == other.Role ||
                     Role != null &&
                     Role.Equals(other.Role)
                 ) &&
                 (
                     VersionGcMaxAgeInSecs == other.VersionGcMaxAgeInSecs ||
                     VersionGcMaxAgeInSecs != null &&
                     VersionGcMaxAgeInSecs.Equals(other.VersionGcMaxAgeInSecs)
                 ) &&
                 (
                     VersionGCExpression == other.VersionGCExpression ||
                     VersionGCExpression != null &&
                     VersionGCExpression.Equals(other.VersionGCExpression)
                 ) &&
                 (
                     VersionGCTimeLimitInSecs == other.VersionGCTimeLimitInSecs ||
                     VersionGCTimeLimitInSecs != null &&
                     VersionGCTimeLimitInSecs.Equals(other.VersionGCTimeLimitInSecs)
                 ) &&
                 (
                     BlobGcMaxAgeInSecs == other.BlobGcMaxAgeInSecs ||
                     BlobGcMaxAgeInSecs != null &&
                     BlobGcMaxAgeInSecs.Equals(other.BlobGcMaxAgeInSecs)
                 ) &&
                 (
                     BlobTrackSnapshotIntervalInSecs == other.BlobTrackSnapshotIntervalInSecs ||
                     BlobTrackSnapshotIntervalInSecs != null &&
                     BlobTrackSnapshotIntervalInSecs.Equals(other.BlobTrackSnapshotIntervalInSecs)
                 ) &&
                 (
                     RepositoryHome == other.RepositoryHome ||
                     RepositoryHome != null &&
                     RepositoryHome.Equals(other.RepositoryHome)
                 ) &&
                 (
                     MaxReplicationLagInSecs == other.MaxReplicationLagInSecs ||
                     MaxReplicationLagInSecs != null &&
                     MaxReplicationLagInSecs.Equals(other.MaxReplicationLagInSecs)
                 ) &&
                 (
                     DocumentStoreType == other.DocumentStoreType ||
                     DocumentStoreType != null &&
                     DocumentStoreType.Equals(other.DocumentStoreType)
                 ) &&
                 (
                     BundlingDisabled == other.BundlingDisabled ||
                     BundlingDisabled != null &&
                     BundlingDisabled.Equals(other.BundlingDisabled)
                 ) &&
                 (
                     UpdateLimit == other.UpdateLimit ||
                     UpdateLimit != null &&
                     UpdateLimit.Equals(other.UpdateLimit)
                 ) &&
                 (
                     PersistentCacheIncludes == other.PersistentCacheIncludes ||
                     PersistentCacheIncludes != null &&
                     PersistentCacheIncludes.Equals(other.PersistentCacheIncludes)
                 ) &&
                 (
                     LeaseCheckMode == other.LeaseCheckMode ||
                     LeaseCheckMode != null &&
                     LeaseCheckMode.Equals(other.LeaseCheckMode)
                 ));
        }
Ejemplo n.º 11
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="PersistentViewStatePersister"/> class.
 /// </summary>
 /// <param name="page">The page.</param>
 /// <param name="cache">The persistent cache.</param>
 public PersistentViewStatePersister(Page page, PersistentCache cache)
     : base(page, cache)
 {
 }
Ejemplo n.º 12
0
        /// <summary>
        ///   Learn how to use KVLite by examples.
        /// </summary>
        public static void Main()
        {
            // Some variables used in the examples.
            var examplePartition1 = "example partition 1";
            var examplePartition2 = "example partition 2";
            var exampleKey1 = "example key 1";
            var exampleKey2 = "example key 2";
            var simpleValue = Math.PI;
            var complexValue = new ComplexValue
            {
                Integer = 21,
                NullableBoolean = null,
                String = "Learning KVLite",
                Dictionary = new Dictionary<short, ComplexValue>
                {
                    [1] = new ComplexValue { NullableBoolean = true },
                    [2] = new ComplexValue { String = "Nested..." }
                }
            };

            /*
             * KVLite stores its values inside a given partition and each value is linked to a key.
             * KVLite can contain more than one partition and each partition can contain more than one key.
             *
             * Therefore, values are stored according to this logical layout:
             *
             * [partition1] --> key1/value1
             *              --> key2/value2
             * [partition2] --> key1/value1
             *              --> key2/value2
             *              --> key3/value3
             *
             * A key is unique inside a partition, not inside all cache.
             * A partition, instead, is unique inside all cache.
             */

            // You can start using the default caches immediately. Let's try to store some values in
            // a way similar to the figure above, using the default persistent cache.
            ICache persistentCache = PersistentCache.DefaultInstance;
            persistentCache.AddTimed(examplePartition1, exampleKey1, simpleValue, persistentCache.Clock.UtcNow.AddMinutes(5));
            persistentCache.AddTimed(examplePartition1, exampleKey2, simpleValue, persistentCache.Clock.UtcNow.AddMinutes(10));
            persistentCache.AddTimed(examplePartition2, exampleKey1, complexValue, persistentCache.Clock.UtcNow.AddMinutes(10));
            persistentCache.AddTimed(examplePartition2, exampleKey2, complexValue, persistentCache.Clock.UtcNow.AddMinutes(5));
            PrettyPrint(persistentCache);

            // Otherwise, you can customize you own cache... Let's see how we can use a volatile
            // cache. Let's define the settings that we will use in new volatile caches.
            var volatileCacheSettings = new VolatileCacheSettings
            {
                CacheName = "My In-Memory Cache", // The backend.
                StaticIntervalInDays = 10 // How many days static values will last.
            };

            // Then the settings that we will use in new persistent caches.
            var persistentCacheSettings = new PersistentCacheSettings
            {
                CacheFile = "CustomCache.sqlite", // The SQLite DB used as the backend for the cache.
                InsertionCountBeforeAutoClean = 10, // Number of inserts before a cache cleanup is issued.
                MaxCacheSizeInMB = 64, // Max size in megabytes for the cache.
                MaxJournalSizeInMB = 16, // Max size in megabytes for the SQLite journal log.
                StaticIntervalInDays = 10 // How many days static values will last.
            };

            // We create both a volatile and a persistent cache.
            var volatileCache = new VolatileCache(volatileCacheSettings);
            persistentCache = new PersistentCache(persistentCacheSettings);

            // Use the new volatile cache!
            volatileCache.AddStatic(examplePartition1, exampleKey1, Tuple.Create("Volatile!", 123));
            PrettyPrint(volatileCache);

            // Use the new persistent cache!
            persistentCache.AddStatic(examplePartition2, exampleKey2, Tuple.Create("Persistent!", 123));
            PrettyPrint(persistentCache);

            /*
             * An item can be added to the cache in three different ways.
             *
             * "Timed" values last until the specified date and time, or for a specified timespan.
             * Reading them will not extend their lifetime.
             *
             * "Sliding" values last for the specified lifetime, but, if read,
             * their lifetime will be extended by the timespan specified initially.
             *
             * "Static" values are a special form of "sliding" values.
             * They use a very long timespan, 30 days by default, and they can be used for seldom changed data.
             */

            // Let's clear the volatile cache and let's a value for each type.
            volatileCache.Clear();
            volatileCache.AddTimed(examplePartition1, exampleKey1, simpleValue, volatileCache.Clock.UtcNow.AddMinutes(10));
            volatileCache.AddTimed(examplePartition1, exampleKey2, complexValue, TimeSpan.FromMinutes(15));
            volatileCache.AddStatic(examplePartition2, exampleKey1, simpleValue);
            volatileCache.AddSliding(examplePartition2, exampleKey2, complexValue, TimeSpan.FromMinutes(15));
            PrettyPrint(volatileCache);

            Console.Read();
        }
Ejemplo n.º 13
0
 public void Dispose_ObjectDisposedExceptionAfterDispose()
 {
     Cache = new PersistentCache(new PersistentCacheSettings());
     Cache.Dispose();
     Assert.Throws <ObjectDisposedException>(() => { Cache.Count(); });
 }
 /// <summary>
 ///   Initializes a new instance of the <see cref="PersistentViewStatePersister"/> class.
 /// </summary>
 /// <param name="page">The page.</param>
 /// <param name="cache">The persistent cache.</param>
 public PersistentViewStatePersister(Page page, PersistentCache cache)
     : base(page, cache)
 {
 }
Ejemplo n.º 15
0
 public void Save()
 {
     PersistentCache.Save(Items);
     GameController.GC.Save();
 }
Ejemplo n.º 16
0
 /// <summary>
 ///   Initializes the provider using the specified cache.
 /// </summary>
 /// <param name="cache">The cache that will be used by the provider.</param>
 public PersistentOutputCacheProvider(PersistentCache cache)
     : base(cache)
 {
 }
Ejemplo n.º 17
0
 /// <summary>
 ///   Initializes the provider using the specified cache.
 /// </summary>
 /// <param name="cache">The cache that will be used by the provider.</param>
 public PersistentOutputCacheProvider(PersistentCache cache)
     : base(cache)
 {
 }
Ejemplo n.º 18
0
 void Save()
 {
     PersistentCache.Save("model", Model);
 }
        public async void TestDiskChurn()
        {
            var path = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}");

            Directory.CreateDirectory(path);
            var store    = new PersistentDiskStore(path);
            var settings = new PersistentCacheOptions()
            {
                FreeSpacePercentGoal    = 50,
                MaxCachedBytes          = 1000,
                MaxWriteLogSize         = 800,
                WriteLogFlushIntervalMs = 1,
                ReadInfoFlushIntervalMs = 1,

                ShardCount = 1,
            };
            var clock = new CacheClock(); //new FakeClock("2020-05-25");
            var cache = new PersistentCache(store, clock, settings);

            try
            {
                await cache.StartAsync(CancellationToken.None);


                var dataBytes = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

                for (int i = 0; i < 10; i++)
                {
                    var key = new CacheKey
                    {
                        Key1 = Encoding.UTF8.GetBytes($"file{i}.jpg"),
                        Key2 = Encoding.UTF8.GetBytes("2020-05-25 00:00:00"),
                        Key3 = Encoding.UTF8.GetBytes("?width=200"),
                    };

                    cache.PutBytesEventually(key, dataBytes, 1);
                }

                await cache.FlushWrites();

                //Thread.Sleep(50);
                //clock.AdvanceSeconds(45);
                Thread.Sleep(2000);
                await cache.FlushWrites();


                for (int i = 0; i < 10; i++)
                {
                    var key = new CacheKey
                    {
                        Key1 = Encoding.UTF8.GetBytes($"file{i}.jpg"),
                        Key2 = Encoding.UTF8.GetBytes("2020-05-25 00:00:00"),
                        Key3 = Encoding.UTF8.GetBytes("?width=200"),
                    };

                    using (var stream = await cache.GetStream(key, CancellationToken.None))
                    {
                        Assert.Equal(0, stream.ReadByte());
                        Assert.Equal(1, stream.ReadByte());
                    }
                }


                var exceptions = cache.PopExceptions();
                foreach (var e in exceptions)
                {
                    throw e;
                }



                await cache.StopAsync(CancellationToken.None);
            }
            finally
            {
                try
                {
                    await cache.StopAsync(CancellationToken.None);
                }
                finally
                {
                    Directory.Delete(path, true);
                }
            }
        }