开发者

Which Android/Java ORM uses “object caching” like Hibernate does?

开发者 https://www.devze.com 2023-03-22 11:53 出处:网络
I saw a bunch of questions about lightweight alternatives to Hibernate, especially for Android. But which of them has the “Identity Map” pattern?

I saw a bunch of questions about lightweight alternatives to Hibernate, especially for Android. But which of them has the “Identity Map” pattern?

This pattern makes sure that any object representing a row in the db exists only once in any session. – It helps my program to be consistent: if I change a mapped object somewhere, it is changed everywhere (because all references point to the same object). It doesn’t matter if I re-fetch the object via a new database query, or still have it around from earlier calls: the ORM makes sure they all behave like the same thing.

Hibernate doe开发者_开发技巧s this in it’s “level 1 cache”.


ORMLite is an Android ORM package that as of version 4.26 (released on 9/26/2011) contains a first take on an internal object cache. ORMLite does not have a "session" pattern but the user can inject a cache into any DAO and can flush it whenever they choose. Here are the docs for the cache support.

http://ormlite.com/docs/object-cache

To quote from the manual, the cache supports the following things:

  • If you create an object using the DAO, it will be added to the cache.
  • When you query for an object using the DAO, if the object is in the cache it will be returned. If it is not in the cache then it will be added to the cache. This does not apply to the raw query methods.
  • If you update an object with the database using the DAO, if it exists in cache it will be updated.
  • If you refresh an object from the database using the DAO, if it exists in cache it will be refreshed.
  • If you delete the object using the DAO, the object will be deleted from the cache.

There are 2 object cache implementations included with the ORMLite core package. One that supports weak/soft references and another that is a standard LRU.

It is [obviously] a very simple implementation compared to Hibernate's level 1 cache. Feedback welcome.


greenDAO supports sessions similar to Hibernate and comes with an identity scope. Within a session, entities are tracked by the ORM layer.


I`m trying to do the same. Have you hear about https://github.com/iainconnor/ObjectCache ?

I`m going to store the length of the list and all item one by one.

Get back to you, if I had done with my own implementation

Cheers,Karoly

0

精彩评论

暂无评论...
验证码 换一张
取 消