All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.datanucleus.cache.package.html Maven / Gradle / Ivy

Go to download

DataNucleus Core provides the primary components of a heterogenous Java persistence solution. It supports persistence API's being layered on top of the core functionality.

There is a newer version: 6.0.7
Show newest version

    This package provides classes implementing caching within DataNucleus.
    There are 2 caches used internally :-
    

The first is within the PersistenceManager and is the Level 1 Cache. There are 3 available implementations of a Level 1 Cache here :- SoftRefCache, WeakRefCache and HardRefCache. They provide varying degrees of object retention during the garbage collection process.

The second is across multiple PersistenceManagers within the same PersistenceManagerFactory, and is the Level 2 Cache. There is one implementation of a Level 2 Cache here :- DefaultLevel2Cache. Alternatively, there are plugins for EHCache, SwarmCache, OSCache and Coherence products

As far as Level 2 caching is concerned each class is configurable via metadata @Cacheable (and equivalent XML). In addition we can define which fields are cacheable using this mechanism, but maybe using @Extension metadata if the persistence API doesn't support field-level restrictions.

At commit of a transaction we check all enlisted objects and have a recursive process that navigates down through all objects to cache (limited by the FetchPlan) and at the end all of these objects will be put in the L2 cache (and logged). Also at this point if any enlisted objects have been deleted during the transaction we remove them from the L2 cache. When an object is to be put in the L2 cache we check if it already has an entry in the L2 cache and, if so, we update that object with the current field values, version, etc. When an object is to be put in the L2 cache and it has relation fields, we don't store the actual objects of those relations instead storing the identities of the related objects in the CachedPC object. When an object is to be taken from the L2 cache we create a copy of that object and copy the field values across for all fields that were loaded when it was originally put in the cache. When a relation field is required to be loaded we use the identities that are stored in the CachedPC, and find the equivalent object for that identity from the L1/L2 caches, reinstating it into the managed object.





© 2015 - 2024 Weber Informatics LLC | Privacy Policy