SQLite Forum

Memory cache
Login

Memory cache

(1) By Levente (levente) on 2021-07-16 07:08:42

Hi all,


I would like to know if there are any cache option available for SQLite.

The problem: I'm developing an application that runs on a low memory device that doesn't have much memory, and I don't want to rely on disk cache. I plan to READ the database very often, say every 50ms, and write every secund. I am afraid of flash wear out.

So my question is if there is any way to read the database from disk, and then copy it to the memory based database, and then write back to disk?

Or is there any other technique that can be used to prevent disk IO?


Thanks,
Lev

(2) By anonymous on 2021-07-16 08:19:11 in reply to 1 [link]

The inverse of the Sqlite3 CLI **.save** to „take from file into Memory“? But  .read and .load have other functions!

(3) By Daniel (rexopl) on 2021-07-16 12:30:10 in reply to 1 [link]

Yes, there is backup() function that can copy DB from/to disk and memory.

Two options:

- :memory: single thread DB - dies after close last connection
- file:db_name?mode=memory&cache=shared - cross thread DB, dies after process exits

Here is example in python3: https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.backup

(4) By Levente (levente) on 2021-07-16 15:18:22 in reply to 3 [link]

Yes, this is exactly what I was looking for. Thanks!