Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 842
Maximilian Stroh Avatar asked Jan 07 '13 23:01

Maximilian Stroh


People also ask

Does ActiveRecord cache?

ActiveRecord makes accessing your database easy, but it can also help make it faster by its intelligent use of caching.

What is ActiveRecord?

Active Record is the M in MVC - the model - which is the layer of the system responsible for representing business data and logic. Active Record facilitates the creation and use of business objects whose data requires persistent storage to a database.

What does ActiveRecord base do?

ActiveRecord::Base indicates that the ActiveRecord class or module has a static inner class called Base that you're extending.

Is ActiveRecord an ORM?

ActiveRecord is an ORM. It's a layer of Ruby code that runs between your database and your logic code. When you need to make changes to the database, you'll write Ruby code, and then run "migrations" which makes the actual changes to the database.


1 Answers

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.

like image 71
Dzmitry Plashchynski Avatar answered Sep 26 '22 00:09

Dzmitry Plashchynski