SQL query cache

29 views
Skip to first unread message

Andrey Markhel

unread,
May 2, 2012, 12:40:58 PM5/2/12
to ActiveJDBC Group
Hi, Igor. As I said earlier I'd implemented sql query(connection)
cache facility. It is appropriate for web-based applications, where
through one request some queries can be repeated and repeated(select *
from people where id = 1) There are no need to ping DB again and
again :), if data wasn't change.
So, I introduce methods in DB.java and Base.java
you can enable sql connection cache by :
1) new DB("default").enableSqlCache().open(driver(), url(), user(),
password());
2) Base.openCached(driver(), url(), user(), password());

After that, all similar requests will be cached. Cache will be purged
automatically if any INSERT\UPDATE\DELETE occurs. Also cache will be
cleared and removed in subsequent DB.close("default") when connection
closed.

Also, implemented cache is smart enough to find semantics equivalence
between "SELECT * from people Where id= ?"(param Long(1)) and
"select * from people where id = ?"(Integer(1)). Both queries is
identical for cache.

Also, for experiment I implement next feature - if results for query
("select * from people") exists, then query (select * from people
limit 2 offset 5) - will not trip to database, but will use data from
cache.

I'd wrote many test cases and comments, please, review branch
sqlQueryCache.

Andrey Markhel

unread,
May 2, 2012, 1:09:25 PM5/2/12
to ActiveJDBC Group
Btw, while implementing, I fix one issue from you tracker - cache
preparement statements everywhere :)

Igor Polevoy

unread,
May 2, 2012, 3:03:43 PM5/2/12
to activejd...@googlegroups.com, Andrey Markhel
Andrey, thanks for the contributions, I will dive into it on the
weekend, super busy now.
DO not worry about criticizing code, I really appreciate it, as you now
when you develop in isolation, you are prone to make stupid mistakes,
so a second pair of eyes is great

thanks
Igor
Reply all
Reply to author
Forward
0 new messages