Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for In Memory JDBC cache #18

Closed
emmanuel-keller opened this issue Oct 19, 2017 · 3 comments
Closed

Add support for In Memory JDBC cache #18

emmanuel-keller opened this issue Oct 19, 2017 · 3 comments
Assignees
Milestone

Comments

@emmanuel-keller
Copy link
Contributor

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:

  • jdbc:cache:file:{path-to-the-cache-directory} for on disk cache
  • jdbc:cache:mem:{name-of-the-cache} for in memory cache
@emmanuel-keller
Copy link
Contributor Author

@dadoonet Thanks for that great patch ! 8226a35

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
Copy link
Contributor

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 emmanuel-keller added this to the v1.3 milestone Apr 6, 2018
@emmanuel-keller
Copy link
Contributor Author

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

#21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants