Exemplo n.º 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);
            }));
        }