public class CouchbaseSessionStore extends Object implements Session.Store
A Session.Store
powered by Couchbase.
{
use(new Couchbase("couchbase://localhost/bucket"));
session(CouchbaseSessionStore.class);
get("/", req -> {
Session session = req.session();
session.put("foo", "bar");
..
});
}
Session data is persisted in Couchbase and document looks like:
{
"session::{SESSION_ID}": {
"foo": "bar"
}
}
By default, a session will expire after 30 minutes
. Changing the default timeout is as simple as:
# 8 hours session.timeout = 8h # 15 seconds session.timeout = 15 # 120 minutes session.timeout = 120m
Expiration is done via Couchbase expiry/ttl option.
If no timeout is required, use -1
.
The session document are persisted in the application/default bucket, if you need/want a different bucket then use Couchbase.sessionBucket(String)
, like:
{
use(
new Couchbase("couchbase://localhost/myapp")
.sessionBucket("session")
);
}
rnd
Constructor and Description |
---|
CouchbaseSessionStore(com.couchbase.client.java.Bucket bucket, int timeout) |
CouchbaseSessionStore(com.couchbase.client.java.Bucket bucket, String timeout) |
Modifier and Type | Method and Description |
---|---|
void |
create(Session session) |
void |
delete(String id)
Delete a session by ID.
|
Session |
get(Session.Builder builder)
Get a session by ID (if any).
|
void |
save(Session session)
Save/persist a session.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
generateID
public CouchbaseSessionStore(com.couchbase.client.java.Bucket bucket, int timeout)
@Inject public CouchbaseSessionStore(@Named(value="session") com.couchbase.client.java.Bucket bucket, @Named(value="session.timeout") String timeout)
public Session get(Session.Builder builder)
Session.Store
get
in interface Session.Store
builder
- A session builder.
null
.
public void save(Session session)
Session.Store
save
in interface Session.Store
session
- A session to be persisted.
public void create(Session session)
create
in interface Session.Store
public void delete(String id)
Session.Store
delete
in interface Session.Store
id
- A session ID.
Copyright © 2019. All rights reserved.