UNPKG

poseidon-memcached

Version:

A future wrapper around the Node Memcached driver using Poseidon.

40 lines (31 loc) 1.3 kB
Driver ====== The `Driver` class stores configurations for multiple caches. It also caches the clients for quick access and reuse. Memcached = require 'memcached' class Driver @_configuration: {} @_connections: {} @configure: (connName, connConfig) -> throw new Error('Configuration object required') unless connConfig? @_configuration[connName] = connConfig.servers return @openConnection: (connName) -> throw Error('Connection not configured') unless @_configuration[connName]? if @_connections[connName]? then return @_connections[connName] @_connections[connName] = new Memcached(@_configuration[connName]) @closeConnection: (connName) -> throw Error('Connection does not exist') unless @_connections[connName]? @_connections[connName].end() delete @_connections[connName] return @reset: () -> for connName, connConfig of @_configuration if @_connections[connName]? then @closeConnection(connName) delete @_configuration[connName] return @shutdown: () -> for connName, connConfig of @_configuration if @_connections[connName]? then @closeConnection(connName) return module.exports = Driver