Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

82 lines (69 sloc) 2.289 kb
using System;
using System.Web;
using ServiceStack.Caching;
using ServiceStack.Text.Common;
using ServiceStack.Web;
namespace ServiceStack
{
public class SessionFactory : ISessionFactory
{
private readonly ICacheClient cacheClient;
public SessionFactory(ICacheClient cacheClient)
{
this.cacheClient = cacheClient;
}
public class SessionCacheClient : ISession
{
private readonly ICacheClient cacheClient;
private string prefixNs;
public SessionCacheClient(ICacheClient cacheClient, string sessionId)
{
this.cacheClient = cacheClient;
this.prefixNs = "sess:" + sessionId + ":";
}
public object this[string key]
{
get
{
return cacheClient.Get<object>(this.prefixNs + key);
}
set
{
JsWriter.WriteDynamic(() =>
cacheClient.Set(this.prefixNs + key, value));
}
}
public void Set<T>(string key, T value)
{
cacheClient.Set(this.prefixNs + key, value);
}
public T Get<T>(string key)
{
return cacheClient.Get<T>(this.prefixNs + key);
}
public bool Remove(string key)
{
return cacheClient.Remove(this.prefixNs + key);
}
public void RemoveAll()
{
cacheClient.RemoveByPattern(this.prefixNs + "*");
}
}
public ISession GetOrCreateSession(IRequest httpReq, IResponse httpRes)
{
var sessionId = httpReq.GetSessionId()
?? httpRes.CreateSessionIds(httpReq);
return new SessionCacheClient(cacheClient, sessionId);
}
public ISession GetOrCreateSession()
{
var request = HostContext.GetCurrentRequest();
return GetOrCreateSession(request, request.Response);
}
public ISession CreateSession(string sessionId)
{
return new SessionCacheClient(cacheClient, sessionId);
}
}
}
Jump to Line
Something went wrong with that request. Please try again.