UNPKG

waffle

Version:

シンプルなWEBアプリケーションフレームワークです。(ALL YOUR NODE ARE BELONG TO US)

72 lines (63 loc) 2.17 kB
/* * Copyright 2012 Katsunori Koyanagi * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ /** * @overview メモリにセッションを保存するストアです。このストアの実運用は推奨されません。 * クラスタリングの際に、他のプロセス間でセッション情報の同期が行われないためです。 */ "use strict"; var SessionStore = require("../utils/SessionStore"); /** * メモリにセッションを保存するストアです。 * <p> * このストアの実運用は推奨されません。 クラスタリングの際に、他のプロセス間でセッション情報の同期が行われず、 * また、アクセスが多い場合にメモリが圧迫されるためです。 * </p> * * @name Extensions#memoryStore * @see Filters#session */ var entries = {}; var lifetimes = {}; var handler = { clear : function(session) { delete entries[session.sessionId]; delete lifetimes[session.sessionId]; }, store : function(session, values) { entries[session.sessionId] = values; lifetimes[session.sessionId] = session.timeout + Date.now(); }, restore : function(session, callback) { if (session.sessionId in entries) { lifetimes[session.sessionId] = session.timeout + Date.now(); callback(entries[session.sessionId]); return; } callback(null); } }; setInterval(function() { var now = Date.now(); for ( var sessionId in lifetimes) { if (lifetimes[sessionId] < now) { handler.clear(sessionId); } } }, 1000); // // expose // exports.instance = new SessionStore(handler, false);