qwazr / jdbc-cache-driver

A JDBC Cache Driver
7 stars 11 forks source link

Add support for In Memory JDBC cache #18

Closed emmanuel-keller closed 6 years ago

emmanuel-keller commented 6 years ago

There are some use cases where we know we have enough memory and we want to be as fast as possible so we just want to hold in memory a ResultSet related to a given Statement.

This commit implements a new type of cache using memory instead of hard disk files.

It uses a naive implementation with ByteArrayStreams which is not recommended for production.

// Initialize the cache driver
Class.forName("com.qwazr.jdbc.cache.Driver");

// Provide the URL and the Class name of the backend driver
Properties info = new Properties();
info.setProperty("cache.driver.url", "jdbc:derby:memory:myDB;create=true");
info.setProperty("cache.driver.class", "org.apache.derby.jdbc.EmbeddedDriver");
// Get your JDBC connection
Connection cnx = DriverManager.getConnection("jdbc:cache:mem:my-memory-cache", info);

The syntax of the URL can be:

emmanuel-keller commented 6 years ago

@dadoonet Thanks for that great patch ! https://github.com/qwazr/jdbc-cache-driver/commit/8226a356c0c2a21fea457448b9b6434c9bafdce7

Do you have any idea of which improvement would make it production ready ? (having the next 1.3 release in mind)

Using a MappedByteBuffer for instance ?

dadoonet commented 6 years ago

Might be a good idea indeed. I took the most naive approach at the beginning but yeah that might work. My goal with all that is to use your library with the on disk or in memory cache system within an elasticsearch plugin. So I need to check if it actually can run in the context of a java application with a security manager.

I'll give it a try.

Note that with the code we have now, we can always add a new implementation easily. In addition to jdbc:cache:mem:my-memory-cache we can add support for use jdbc:cache:mmap:my-memory-cache. WDYT?

emmanuel-keller commented 6 years ago

we can add support for use jdbc:cache:mmap:my-memory-cache.

https://github.com/qwazr/jdbc-cache-driver/issues/21