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); } }
/// <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)); }
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(); } }
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()); } }
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()); } } }
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; }
/// <summary> /// Constructor /// </summary> /// <param name="cache">Sqlite persistance cache</param> public DataStorage(SQLitePersistentBlobCache cache) { _cache = cache; }