EnterpriseCacheSessionDAO类主要定义了,它继承了CachingSessionDAO抽象类,现对其解析如下:
1.CachingSessionDAO抽象类
可以参考CachingSessionDAO抽象类,主要定义了在缓存中保存session,更新session,删除session,读取session,获取所有的session集合等操作。
2.EnterpriseCacheSessionDAO类
2.1.构造方法
public EnterpriseCacheSessionDAO() {
setCacheManager(new AbstractCacheManager() {
@Override
protected Cache<Serializable, Session> createCache(String name) throws CacheException {
return new MapCache<Serializable, Session>(name, new ConcurrentHashMap<Serializable, Session>());
}
});
}
2.2.创建session(它实现了CachingSessionDAO接口的方法)
protected Serializable doCreate(Session session) {
Serializable sessionId = generateSessionId(session);
assignSessionId(session, sessionId);
return sessionId;
}
2.3.根据sessionId读取session信息(它实现了CachingSessionDAO接口的方法)
protected Session doReadSession(Serializable sessionId) {
return null;
}
2.4.更新操作(它实现了CachingSessionDAO接口的方法)
protected void doUpdate(Session session) {
//does nothing - parent class persists to cache.
}
2.5.删除操作(它实现了CachingSessionDAO接口的方法)
protected void doDelete(Session session) {
//does nothing - parent class removes from cache.
}
EnterpriseCacheSessionDAO是Spring Session的一个实现,继承自CachingSessionDAO。它提供了创建、读取、更新和删除session的功能。在构造方法中,通过AbstractCacheManager创建了一个基于ConcurrentHashMap的MapCache。doCreate方法生成并分配sessionId,doReadSession用于根据sessionId获取session,但在这里返回null。doUpdate和doDelete方法默认不做任何操作,因为父类负责缓存管理。
1万+

被折叠的 条评论
为什么被折叠?



