Ejemplo n.º 1
0
        public CreateSessionResult <IReadOnlyCacheSession> CreateReadOnlySession(Context context, string name, ImplicitPin implicitPin)
        {
            Contract.Requires(ContentStore != null);
            Contract.Requires(MemoizationStore != null);

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

                var contentReadOnlySession = createContentResult.Session;

                var createMemoizationResult = MemoizationStore.CreateReadOnlySession(context, name);
                if (!createMemoizationResult)
                {
                    return new CreateSessionResult <IReadOnlyCacheSession>(createMemoizationResult, "Memoization session creation failed");
                }

                var memoizationReadOnlySession = createMemoizationResult.Session;

                var session = new ReadOnlyOneLevelCacheSession(name, implicitPin, memoizationReadOnlySession, contentReadOnlySession);
                return new CreateSessionResult <IReadOnlyCacheSession>(session);
            }));
        }