Example #1
0
 public AkavacheConfiguration()
 {
     var commonAppSettings = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
     var container = Path.Combine(commonAppSettings, DIRECTORY);
     if (!Directory.Exists(container))
         Directory.CreateDirectory(container);
     var storagePath = Path.Combine(container, FILENAME);
     this.cache = new Akavache.Sqlite3.SQLitePersistentBlobCache(storagePath);
 }
 /// <summary>
 /// Gets storage version
 /// </summary>
 /// <param name="cache">Cache</param>
 /// <returns>Storage version</returns>
 public static int?TryGetDbVersion(SQLitePersistentBlobCache cache)
 {
     try
     {
         return(cache.Connection.ExecuteScalar <int>("PRAGMA user_version;"));
     }
     catch
     {
         return(null);
     }
 }
Example #3
0
        /// <summary>
        /// Opens cache.
        /// </summary>
        /// <param name="file">Storage file name</param>
        /// <param name="dbVersion">Storage version</param>
        /// <returns>Return cache and storage initializer pair</returns>
        private static Tuple <SQLitePersistentBlobCache, IStorageInitializer> OpenCache(ILocalFile file, int dbVersion)
        {
            var fullDbFileName = file.FullFileName;

            var cache           = new SQLitePersistentBlobCache(fullDbFileName);
            var actualDbVersion = StorageInitializer.TryGetDbVersion(cache);
            IStorageInitializer dataStorageInitializer = null;

            if (actualDbVersion.HasValue == false || actualDbVersion.Value != dbVersion)
            {
                dataStorageInitializer = new StorageInitializer(cache, dbVersion);
            }

            return(new Tuple <SQLitePersistentBlobCache, IStorageInitializer>(cache, dataStorageInitializer));
        }
Example #4
0
        public async Task GroupedRequestsWithDifferentKeysReturnEmptyResultIfItemsDontExist()
        {
            using (Utility.WithEmptyDirectory(out var path))
            {
                using (var cache = new SQLitePersistentBlobCache(Path.Combine(path, "sqlite.db")))
                {
                    var queue            = new SqliteOperationQueue(cache.Connection, BlobCache.TaskpoolScheduler);
                    var request          = queue.Select(new[] { "Foo" });
                    var unrelatedRequest = queue.Select(new[] { "Bar" });

                    cache.ReplaceOperationQueue(queue);

                    Assert.Equal(0, (await request).Count());
                    Assert.Equal(0, (await unrelatedRequest).Count());
                }
            }
        }
        public IBlobCache CreateBlobCache(string path)
        {
            Guard.ArgumentNotEmptyString(path, nameof(path));
            if (cache.ContainsKey(path))
                return cache[path];

            try
            {
                var c = new SQLitePersistentBlobCache(path);
                cache.Add(path, c);
                return c;
            }
            catch(Exception ex)
            {
                log.Error("Error while creating SQLitePersistentBlobCache for {0}. {1}", path, ex);
                return new InMemoryBlobCache();
            }
        }
Example #6
0
        public IBlobCache CreateBlobCache(string path)
        {
            Guard.ArgumentNotEmptyString(path, nameof(path));
            if (cache.ContainsKey(path))
            {
                return(cache[path]);
            }

            try
            {
                var c = new SQLitePersistentBlobCache(path);
                cache.Add(path, c);
                return(c);
            }
            catch (Exception ex)
            {
                log.Error(ex, "Error while creating SQLitePersistentBlobCache for {Path}", path);
                return(new InMemoryBlobCache());
            }
        }
Example #7
0
        public async Task GroupedRequestsWithDifferentKeysReturnEmptyResultIfItemsDontExist()
        {
            string path;

            using (Utility.WithEmptyDirectory(out path))
            {
                using (var cache = new SQLitePersistentBlobCache(Path.Combine(path, "sqlite.db")))
                {
                    var queue = new SqliteOperationQueue(cache.Connection, BlobCache.TaskpoolScheduler);
                    var request = queue.Select(new[] { "Foo" });
                    var unrelatedRequest = queue.Select(new[] { "Bar" });

                    cache.ReplaceOperationQueue(queue);

                    Assert.Equal(0, (await request).Count());
                    Assert.Equal(0, (await unrelatedRequest).Count());
                }
            }
        }
Example #8
0
 public AkavacheDriver(string path, ICacheSerializer serializer)
 {
     Cache      = new SQLitePersistentBlobCache(path);
     Serializer = serializer;
     Log.Debug("Akavache Cache Driver Initialized at '{Path}'", path);
 }
 /// <summary>
 /// Sets storage version.
 /// </summary>
 /// <param name="cache">SQLite persistent cache</param>
 /// <param name="dbVersion">Db version</param>
 private static void SetDbVersion(SQLitePersistentBlobCache cache, int dbVersion)
 {
     cache.Connection.Execute("PRAGMA user_version = " + dbVersion);
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="cache">Cache</param>
 /// <param name="targetDbVersion">Target db version</param>
 public StorageInitializer(SQLitePersistentBlobCache cache, int targetDbVersion)
 {
     _cache           = cache;
     _targetDbVersion = targetDbVersion;
 }
Example #11
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="cache">Sqlite persistance cache</param>
 public DataStorage(SQLitePersistentBlobCache cache)
 {
     _cache = cache;
 }