/// <summary> /// Initializes a new instance of the <see cref="OneLevelCache" /> class. /// </summary> public OneLevelCache(Func <IContentStore> contentStoreFunc, Func <IMemoizationStore> memoizationStoreFunc, Guid id) { Contract.Requires(contentStoreFunc != null); Contract.Requires(memoizationStoreFunc != null); ContentStore = contentStoreFunc(); MemoizationStore = memoizationStoreFunc(); Id = id; }
static async Task <int> RunStore(Context context, IMemoizationStore store) { try { try { StartupResult startupResult = await store.StartupAsync(context).ConfigureAwait(false); if (startupResult.HasError) { throw new CacheException($"Failed to start store, error=[{startupResult.ErrorMessage}]"); } var createSessionResult = store.CreateSession(context, "sample"); if (createSessionResult.HasError) { throw new CacheException($"Failed to create session, error=[{createSessionResult.ErrorMessage}]"); } using (var session = createSessionResult.Session) { try { var sessionStartupResult = session.StartupAsync(context).Result; if (sessionStartupResult.HasError) { throw new CacheException($"Failed to start session, error=[{createSessionResult.ErrorMessage}]"); } } finally { var sessionShutdownResult = session.ShutdownAsync(context).Result; if (sessionShutdownResult.HasError) { context.Error($"Failed to shutdown session, error=[{sessionShutdownResult.ErrorMessage}]"); } } } } finally { ShutdownResult shutdownResult = await store.ShutdownAsync(context).ConfigureAwait(false); if (shutdownResult.HasError) { context.Error($"Failed to shutdown store, error=[{shutdownResult.ErrorMessage}]"); } } return(0); } catch (Exception) { return(1); } }
/// <summary> /// Initializes a new instance of the <see cref="OneLevelCache" /> class. /// </summary> /// <remarks> /// It is assumed that the produced sessions are different objects. /// </remarks> public OneLevelCache(Func <IContentStore> contentStoreFunc, Func <IMemoizationStore> memoizationStoreFunc, Guid id) { Contract.Requires(contentStoreFunc != null); Contract.Requires(memoizationStoreFunc != null); ContentStore = contentStoreFunc(); MemoizationStore = memoizationStoreFunc(); Id = id; Contract.Assert(!ReferenceEquals(ContentStore, MemoizationStore)); }
private async Task <List <StrongFingerprint> > EnumerateStrongFingerprintsAsync(Context context, IMemoizationStore store, int count) { var asyncEnumerator = store.EnumerateStrongFingerprints(context).GetAsyncEnumerator(); var strongFingerprints = new List <StrongFingerprint>(); for (int i = 0; i < count && await asyncEnumerator.MoveNextAsync() && asyncEnumerator.Current.Succeeded; i++) { strongFingerprints.Add(asyncEnumerator.Current.Data); } return(strongFingerprints); }