Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ An elastic-search based session driver for Laravel 5.1
"elastic" => [
"url" => "http://localhost:9200/",
"index" => "laravel-es-sessions",
"type" => "session"
"type" => "session",
'ttl' => '15m' //check https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-ttl-field.html#_default_ttl
],
```
Values shown above are the default values in case you did not configure.
Expand All @@ -42,6 +43,10 @@ You can do so manually by applying this mapping to the index and type:
"created":{"type":"date"},
"updated":{"type":"date"},
"data":{"type":"string","index":"no"}
},
"_ttl":{
"enabled":true,
"default":"15m"
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/ElasticSessionStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public static function putMapping() {
'created' => ['type' => 'date'],
'updated' => ['type' => 'date'],
'data' => ['type' => 'string', 'index' => 'no'],
]
],
'_ttl' => (@$config['ttl'] ? ['enabled' => true, 'default' => @$config['ttl']? : '15m'] : ['enabled' => false])
]
];
$client->indices()->putMapping($mappingParams);
Expand Down Expand Up @@ -74,7 +75,7 @@ public function read($sessionId) {
public function write($sessionId, $sessionData) {
$updatedTs = Carbon::now()->toIso8601String();
$createdTs = array_key_exists($sessionId, $this->_cache) ? $this->_cache[$sessionId]->created : $updatedTs;
static::create(['data' => $sessionData, 'created' => $createdTs, 'updated' => $updatedTs], $sessionId, ["api" => "index"]);
static::create(['data' => $sessionData, 'created' => $createdTs, 'updated' => $updatedTs, '_ttl' => config('session.elastic.ttl', '15m')], $sessionId, ["api" => "index"]);
}

public function destroy($sessionId) {
Expand Down