Exemple #1
0
        public CreateSessionResult <ICacheSession> CreateSession(Context context, string name, ImplicitPin implicitPin)
        {
            Contract.Requires(ContentStore != null);
            Contract.Requires(MemoizationStore != null);

            return(Tracing.CreateSessionCall.Run(CacheTracer, context, name, () =>
            {
                var createContentResult = ContentStore.CreateSession(context, name, implicitPin);
                if (!createContentResult)
                {
                    return new CreateSessionResult <ICacheSession>(createContentResult, "Content session creation failed");
                }

                var contentSession = createContentResult.Session;

                var createMemoizationResult = _passContentToMemoization
                    ? MemoizationStore.CreateSession(context, name, contentSession)
                    : MemoizationStore.CreateSession(context, name);

                if (!createMemoizationResult)
                {
                    return new CreateSessionResult <ICacheSession>(createMemoizationResult, "Memoization session creation failed");
                }

                var memoizationSession = createMemoizationResult.Session;

                var session = new OneLevelCacheSession(name, implicitPin, memoizationSession, contentSession);
                return new CreateSessionResult <ICacheSession>(session);
            }));
        }
Exemple #2
0
        protected override Task RunTestAsync(
            Context context, DisposableDirectory testDirectory, Func <IMemoizationStore, IMemoizationSession, Task> funcAsync, Func <DisposableDirectory, IMemoizationStore> createStoreFunc = null)
        {
            return(RunTestAsync(
                       context,
                       testDirectory,
                       async store =>
            {
                var configuration = ContentStoreConfiguration.CreateWithMaxSizeQuotaMB(1);
                var configurationModel = new ConfigurationModel(configuration);

                using (var contentStore = new FileSystemContentStore(
                           FileSystem, SystemClock.Instance, testDirectory.Path, configurationModel))
                {
                    try
                    {
                        var startupContentStoreResult = await contentStore.StartupAsync(context);
                        startupContentStoreResult.ShouldBeSuccess();

                        var contentSessionResult = contentStore.CreateSession(context, Name, ImplicitPin.None);
                        contentSessionResult.ShouldBeSuccess();

                        var sessionResult = store.CreateSession(context, Name, contentSessionResult.Session);
                        sessionResult.ShouldBeSuccess();

                        using (var cacheSession = new OneLevelCacheSession(Name, ImplicitPin.None, sessionResult.Session, contentSessionResult.Session))
                        {
                            try
                            {
                                var r = await cacheSession.StartupAsync(context);
                                r.ShouldBeSuccess();

                                await funcAsync(store, cacheSession);
                            }
                            finally
                            {
                                var r = await cacheSession.ShutdownAsync(context);
                                r.ShouldBeSuccess();
                            }
                        }
                    }
                    finally
                    {
                        var shutdownContentStoreResult = await contentStore.ShutdownAsync(context);
                        shutdownContentStoreResult.ShouldBeSuccess();
                    }
                }
            },
                       createStoreFunc));
        }