Bean IUD invalidation

Cache invalidation is automatically provided for persisted beans. The cache invalidation is processed by bean type and id value.

Cluster message

The message sent around the cluster contains the bean type and 3 lists of ids - a list of id values for inserted, updated and deleted beans.

L2 query cache

  • Inserts, updates or deletes: Invalidate the entire L2 query cache for the bean type

For any bean persist event invalidates the entire related L2 query cache for the associated bean type. For example, saving a customer bean invalidates the entire L2 query cache for the Customer bean type.

L2 bean cache

  • Inserts: Do not effect the L2 bean cache
  • Updates: An entry is updated with changes
  • Deletes: An entry is removed from the L2 bean cache based on the id value

Table IUD invalidation (Bulk updates)

Bulk insert, update or delete events are processed by table. For a given table the bean types that depend on that table are determined and then for each bean type the L2 bean cache and L2 query cache are invalidated as necessary.

Cluster message

The message sent around the cluster contains the table name and boolean flags for insert, update and delete.

L2 query cache

  • Inserts, updates or deletes: Invalidate the entire L2 query cache for the related bean type

For any bulk statements (bulk table insert, update or delete statement) the entire L2 query cache is invalidated for the associated bean type. For example, a bulk update of the customer table invalidates the entire L2 query cache for the Customer bean type.

L2 bean cache

  • Inserts: Do not effect the L2 bean cache
  • Updates: Invalidate the entire L2 bean cache for the related bean type
  • Deletes: Invalidate the entire L2 bean cache for the related bean type

Explicit invalidation

We can perform explicit invalidation using application code. We want to do this when data is modified externally to Ebean. For example, data is updated by other frameworks, JDBC code etc. For this case we want to explicitly invalidate parts of the L2 cache.

Using externalModification()

// inform Ebean that some rows have been inserted and updated
// on the country table.
// ... Ebean will invalidate the appropriate caches
boolean inserts = true;
boolean updates = true;
boolean deletes = false;
DB.externalModification("country", inserts, updates, deletes);

Using ServerCacheManager

ServerCacheManager also provides explicit API for clearing caches.

// clearAll() caches via the ServerCacheManager ...
ServerCacheManager cacheManager = database.cacheManager();

// Clear all the caches on the default/primary EbeanServer
cacheManager.clearAll();

// clear both the bean and query cache
// for Country beans ...
cacheManager.clear(Country.class);