Advanced Apache Cayenne

2,007 views
1,843 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,007
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Advanced Apache Cayenne

  1. 1. Advanced Apache Cayenne(practical demonstration)by Andrus Adamchik, ObjectStyle LLC
  2. 2. CMS:Admin appTapestry stack
  3. 3. Admin App(demo)
  4. 4. Admin App - Takeaway• We can reuse Cayenne and service code between the apps• When editing objects, ObjectContext is placed in the page scopeand should be reset when we start editing a new object• Scope in Tapestry is managed with @Persist annotation
  5. 5. Lifecycle Events(demo)
  6. 6. Lifecycle Events - Takeway• Two ways to receive events - callbacks and listeners• Use callbacks on persistent objects for simple things likeinitialization• Use listeners for more complex workflows, cross-entityworkflows• Check out DataChannelFilter (will be discussed later)
  7. 7. Caching
  8. 8. Types of Cache• What is cached?• Object cache - objects cached by ID• Query cache - lists cached by generated cache key
  9. 9. Types of Cache• Where is it cached?• Local cache - attached to an ObjectContext• Shared cache - attached to a DataDomain (a common parentof all ObjectContexts)
  10. 10. 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 orVMs• Memory leak-free (shared - LRU; local - weak refs)
  11. 11. 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 (inVM, cross-VM)• Scales much better
  12. 12. Query Cache(demo)
  13. 13. Caching and Performance
  14. 14. Turn off Cross-ContextSynchronization• 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 sameVM vsdifferentVM• Object auto-sync will interfere with optimistic locking
  15. 15. Turn off Cross-ContextSynchronizationbinder.bindMap(Constants.PROPERTIES_MAP).put(Constants.SERVER_CONTEXTS_SYNC_PROPERTY, "false");
  16. 16. 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 tobreaking on code version changes
  17. 17. Consider Optimistic Locking
  18. 18. Caching and Performance• Don’t try to sync individual objects• Turn off cross-context synchronization• Use query cache. Cluster it.• Use optimistic locking
  19. 19. Q&AAndrus Adamchikandrus@objectstyle.comtwitter.com/andrus_a

×