memento-mysql

1.0.2 • Public • Published
Memento - MySQL query caching for Node.js
------------------------------------------------------

>> About

Memento is a MySQL query caching module for Node.js. 
Memento uses memcached to improve Node.js applications 
performance.

>> Quick benchmarks

The following queries were ran against one table with
100 000 rows of random data. These are the execution
times to return all rows from each query:

"SELECT * FROM test WHERE id>10000 LIMIT 1"

	Without Memento : 0.023 seconds
	With Memento : 0.011 seconds	

"SELECT * FROM test WHERE id>10000 LIMIT 250"

	Without Memento : 0.027 seconds
	With Memento : 0.012 seconds	

"SELECT * FROM test WHERE id>10000 LIMIT 1000"

	Without Memento : 0.033 seconds
	With Memento : 0.014 seconds	

"SELECT * FROM test WHERE id>10000 LIMIT 2500"

	Without Memento : 0.042 seconds
	With Memento : 0.018 seconds	

"SELECT * FROM test WHERE id>10000 LIMIT 5000"

	Without Memento : 0.063 seconds
	With Memento : 0.025 seconds	

>> Required modules

Memento needs the following modules to run:

node-mysql (https://github.com/felixge/node-mysql)

node-memcached (https://github.com/3rd-Eden/memcached)

>> Installation

	$ npm install memento-mysql
	
>> Usage

Query usage is very similar to node.js mysql module;

	var Memento = require('memento-mysql');

	var mysqlConfig = {
		host     : 'localhost',
		user     : 'root',
		password : '',
		database : 'test'
	};

	var memcachedConfig = "127.0.0.1:11211";

	var memento = new Memento({
		mysql: mysqlConfig, 
		memcached: memcachedConfig
	});

	memento.query('SELECT * FROM test LIMIT 1', 
		function(err, rows, fields) {
			if (err) throw err;

			console.log(rows);
			
			memento.finish();
		}
	);
	
Memento needs to be initialized with both the MySQL
connection configuration object and the Memcached 
connection configuration object. Both these objects
are the same you would normally pass to the MySQL module
and the Memcached module.

The queries are cached for 5 minutes (300 seconds) by
default. You can change the timeout value in seconds
by changing	the cacheTimeout variables;

	memento.cacheTimeout = 900; // 15 minutes

Once you are done with Memento, you need to call the
finish() method to clean up the connections.

------------------------------------------------------
https://github.com/maxlabelle/Memento

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    1
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i memento-mysql

Weekly Downloads

1

Version

1.0.2

License

BSD-4-Clause

Last publish

Collaborators

  • maxlabelle