public static final class H.Session extends H.KV<H.Session>
String type value, and will be persisted at
client side as a cookie. This means the entire size of the
information stored in session including names and values shall
not exceed 4096 bytes.
To store typed value or big value, use the cache methods of the session class. However it is subject to the implementation to decide whether cache methods are provided and how it is implemented
| Modifier and Type | Field and Description |
|---|---|
static String |
KEY_AUTHENTICITY_TOKEN
Stores the authenticity token in the session
|
static String |
KEY_EXPIRATION
Stores the expiration date in the session
|
static String |
KEY_EXPIRE_INDICATOR
Used to mark if a session has just expired
|
static String |
KEY_FINGER_PRINT
Stores the fingerprint to the session
|
static String |
KEY_ID
Session identifier
|
| Constructor and Description |
|---|
Session() |
| Modifier and Type | Method and Description |
|---|---|
H.Session |
cache(String key,
Object obj)
Store an object into cache using key specified.
|
H.Session |
cache(String key,
Object obj,
int expiration)
Store an object into cache with expiration specified
|
<T> T |
cached(String key)
Retrieve an object from cache by key.
|
<T> T |
cached(String key,
Class<T> clz)
Retrieve an object from cache by key.
|
H.Session |
cacheFor10Min(String key,
Object obj)
Store an object into cache for 10 minutes
|
H.Session |
cacheFor1Hr(String key,
Object obj)
Store an object into cache for 1 hour
|
H.Session |
cacheFor1Min(String key,
Object obj)
Store an object into cache for 1 minutes
|
H.Session |
cacheFor30Min(String key,
Object obj)
Store an object into cache for 30 minutes
|
static H.Session |
current()
Return a session instance of the current execution context,
For example from a
ThreadLocal |
static void |
current(H.Session session)
Set a session instance into the current execution context,
for example into a
ThreadLocal |
boolean |
empty()
Returns
true if the session is empty. |
boolean |
equals(Object obj) |
H.Session |
evict(String key)
Evict an object from cache
|
boolean |
expired()
Check if the session is expired.
|
H.Session |
expireOn(long expiry)
Set session expiry in milliseconds
|
long |
expiry()
Returns the expiration time in milliseconds of this session.
|
String |
id()
Returns the session identifier
|
boolean |
isEmpty()
Returns
true if internal data map is empty |
static H.Session |
resolve(H.Cookie sessionCookie,
int ttl)
Resolve a Session instance from a session cookie
|
H.Cookie |
serialize(String sessionKey)
Serialize this session into a cookie.
|
public static final String KEY_ID
public static final String KEY_EXPIRATION
public static final String KEY_AUTHENTICITY_TOKEN
public static final String KEY_EXPIRE_INDICATOR
public static final String KEY_FINGER_PRINT
public String id()
public boolean empty()
true if the session is empty. e.g.
does not contain anything else than the timestamppublic boolean isEmpty()
H.KVtrue if internal data map is emptypublic boolean expired()
System.currentTimeMillis()true if the session is expiredpublic long expiry()
-1-1 if the session has no
expirypublic H.Session expireOn(long expiry)
expiry - the difference, measured in milliseconds, between
the expiry and midnight, January 1, 1970 UTC.public H.Session cache(String key, Object obj)
The object is cached for default ttl
key - the key to cache the objectobj - the object to be cachedpublic H.Session cache(String key, Object obj, int expiration)
key - the key to cache the objectobj - the object to be cachedexpiration - specify the cache expiration in secondscache(String, Object)public H.Session cacheFor1Hr(String key, Object obj)
key - the key to cache the objectobj - the object to be cachedpublic H.Session cacheFor30Min(String key, Object obj)
key - the key to cache the objectobj - the object to be cachedpublic H.Session cacheFor10Min(String key, Object obj)
key - the key to cache the objectobj - the object to be cachedpublic H.Session cacheFor1Min(String key, Object obj)
key - the key to cache the objectobj - the object to be cachedpublic H.Session evict(String key)
key - the key to cache the objectpublic <T> T cached(String key)
T - the object typekey - the key to get the cached objectnull
if it cannot find the object by key
specifiedcache(String, Object)public <T> T cached(String key, Class<T> clz)
T - the object typekey - the key to get the cached objectclz - the class to specify the return typenull
if it cannot find the object by key
specifiedcache(String, Object)public static H.Session current()
ThreadLocalpublic static void current(H.Session session)
ThreadLocalsession - the session to be set to current execution contextpublic static H.Session resolve(H.Cookie sessionCookie, int ttl)
sessionCookie - the cookie corresponding to a sessionttl - session time to live in secondsserialize(String)public H.Cookie serialize(String sessionKey)
sessionKey - the cookie name for the session cookienull if
this session is empty or this session hasn't been changed and
there is no expiryresolve(org.osgl.http.H.Cookie, int)Copyright © 2017. All Rights Reserved.