Search code examples
ruby-on-railssqlitejrubyrails-activerecordin-memory-database

activerecord in-memory shared cache


Is possible to use the "shared cache" of sqlite3 through activerecord? (see: http://www.sqlite.org/inmemorydb.html)

I use activerecord standalone (without rails) in a JRuby Swing App, with some Worker-Threads involved. Problem: ONLY the main thread can access the data, since every thread rebuilds a new in-memory DB. So i get just

[SQLITE_ERROR] SQL error or missing database (no such table: insert_model_name)

from everywhere, except the main thread. Is there a workaround or did I miss something? (i use the latest versions of jruby, java, and the gems)

Thanks in advance!

Database-Config so far: https://gist.github.com/4482423

UPDATE: Minimal script to illustrate the problem. It runs well under Linux but not in WIndows 7: https://gist.github.com/4483617


Solution

  • The following token works well:
    "file::memory:?cache=shared"
    Also, check your SQLite version, it should be at least 3.7.13 to support this feature.