advanced apache cayenne

20
Advanced Apache Cayenne (practical demonstration) by Andrus Adamchik, ObjectStyle LLC

Upload: wo-community

Post on 19-May-2015

1.642 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Advanced Apache Cayenne

Advanced Apache Cayenne(practical demonstration)by Andrus Adamchik, ObjectStyle LLC

Page 2: Advanced Apache Cayenne
Page 3: Advanced Apache Cayenne

CMS: Admin appTapestry stack

Page 4: Advanced Apache Cayenne

Admin App(demo)

Page 5: Advanced Apache Cayenne

Admin App - Takeaway

• We can reuse Cayenne and service code between the apps

• When editing objects, ObjectContext is placed in the page scope and should be reset when we start editing a new object

• Scope in Tapestry is managed with @Persist annotation

Page 6: Advanced Apache Cayenne

Lifecycle Events(demo)

Page 7: Advanced Apache Cayenne

Lifecycle Events - Takeway

• Two ways to receive events - callbacks and listeners

• Use callbacks on persistent objects for simple things like initialization

• Use listeners for more complex workflows, cross-entity workflows

• Check out DataChannelFilter (will be discussed later)

Page 8: Advanced Apache Cayenne

Caching

Page 9: Advanced Apache Cayenne

Types of Cache

• What is cached?

• Object cache - objects cached by ID

• Query cache - lists cached by generated cache key

Page 10: Advanced Apache Cayenne

Types of Cache

• Where is it cached?

• Local cache - attached to an ObjectContext

• Shared cache - attached to a DataDomain (a common parent of all ObjectContexts)

Page 11: Advanced Apache Cayenne

Object Cache (very much like EOF)

• Stores objects (or DataRows) by ObjectId

• Prevents unneeded DB trips when navigating object graph

• Ensures uniquing

• Can be auto-synchronized across contexts or VMs

• Memory leak-free (shared - LRU; local - weak refs)

Page 12: Advanced Apache Cayenne

Query Cache (nothing like EOF)

• Stores lists of objects (or lists of DataRows) by query key

• Prevents unneeded DB trips when running queries

• Fully “managed” - time-based or event-based expiration policies

• Lightweight synchronization via cache groups (in VM, cross-VM)

• Scales much better

Page 13: Advanced Apache Cayenne

Query Cache(demo)

Page 14: Advanced Apache Cayenne

Caching and Performance

Page 15: Advanced Apache Cayenne

Turn off Cross-Context Synchronization

• Good for desktop apps, terrible for webapps

• unrelated contexts receiving events they don’t care about

• Clustering of object cache doesn’t perform well

• Without clustering, behavior differs for contexts in same VM vs different VM

• Object auto-sync will interfere with optimistic locking

Page 16: Advanced Apache Cayenne

Turn off Cross-Context Synchronization

binder.bindMap(Constants.PROPERTIES_MAP).put(Constants.SERVER_CONTEXTS_SYNC_PROPERTY, "false");

Page 17: Advanced Apache Cayenne

Use Query Cache

• Design your app with cache groups in mind

• Implement refresh based on expiration policies

• Implement refresh based on events and CacheInvalidationFilter

• Cluster refresh events. Clustering is lightweight, not prone to breaking on code version changes

Page 18: Advanced Apache Cayenne

Consider Optimistic Locking

Page 19: Advanced Apache Cayenne

Caching and Performance

• Don’t try to sync individual objects

• Turn off cross-context synchronization

• Use query cache. Cluster it.

• Use optimistic locking