Simple Spring Memcached

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite & 1 Event

    Simple Spring Memcached - Presentation Transcript

    1. Simple-Spring-Memcached http://code.google.com/p/simple-spring-memcached/ A library that enables your code to benefit from distributed caching (via memcached), with minimal configuration and simple annotations.
    2. Bio
      • Nelz Carpentier
      • Sr. Software Engineer at Widgetbox, Inc
      • 10+ Years as a Software Engineer
      • http://www.nelz.net/
      • http://www.twitter.com/nelz9999
      • http://www.linkedin.com/in/nelz9999
    3. Target Audience
      • Technical Folks
      • Familiar with Spring
      • May be interested in adding Memcached
      • Understand the basics of Caching
      • Understand the basics of Distributed Caching
    4. Target Code / Infrastructure
      • Java
      • Spring
      • Serializable / Externalizable Objects
      • High-Read, Low-Write
      • You control (or can wrap) the methods you want to cache
      • Expensive Read Operations
      • Operational Ability to Support Memcached
    5. SSM's Niche
    6. Motivation
      • Broke New Ground?
      • Share My Learnings
      • Self-Evident Concept
      • Not Too Smart
        • Willing to do the work
    7. Shoulders of Giants
      • Build
        • Maven
        • Cobertura
      • Test
        • TestNG
        • EasyMock
        • Mirror
      • Runtime
        • Spy Memcached
        • Spring / AspectJ
        • Log4J
    8. Desired Characteristics of Caching
      • Needed in many layers
      • Should be transparent to main code flow
      • Similar characteristics
        • Logging
        • Security
      • Cross-cutting concern?
      • AOP to the Rescue!
    9. Configure the ApplicationContext
      • <import resource=&quot;classpath:simplesm-context.xml&quot; />
      • <bean id=&quot;memcachedConnectionBean&quot; class=
      • &quot;net.nelz.simplesm.config.MemcachedConnectionBean&quot;>
      • <property name=&quot;consistentHashing&quot; value=&quot;true&quot; />
      • <property name=&quot;nodeList&quot; value=&quot;127.0.0.1:11211 127.0.0.1:11311&quot; />
      • </bean>
      • <aop:aspectj-autoproxy />
    10. Pseudocode of Read Through Scenario
      • $key = calculateValueCacheName()
      • if cacheHasKey($key), return getFromCache($key)
      • $value = doExpensiveRequestForValue()
      • storeInCache($key, $value)
      • return $value
      • Gets info out of the cache
      • Also back door of putting info into the cache
      • [PS: Pertinent Negative Null]
    11. Generating Keys
      • 255 Characters
      • Key + Namespace + Other Characters (~16)
      • No Spaces
      • Default: toString()
      • Preferred: @CacheKeyMethod
    12. Why Namespaces?
      • Avoid Collisions
      • Example:
        • Primary Keys
        • Bad: 123 vs 123
        • Good: Vet:123 vs Pet:123
    13. RTA - Example
      • @ReadThroughAssignCache(
      • assignedKey = &quot;InTheWindow&quot;,
      • namespace = &quot;DOG&quot;,
      • expiration = 300)
      • Dog getDogInWindow() {
      • ...
      • }
    14. RTS – Example 1
      • @ReadThroughSingleCache(
      • keyIndex = 0,
      • namespace = &quot;VETS&quot;,
      • expiration = 300)
      • Vet getVet(Long id) {
      • ...
      • }
    15. RTS – Example 2
      • @ReadThroughSingleCache(
      • keyIndex = 1,
      • namespace = &quot;VETS&quot;,
      • expiration = 300)
      • Vet getVet(Credentials cred, Long id) {
      • ...
      • }
    16. Cardinality Options
      • 1-to-1, 1-to-Many, Invariant
        • “ KEY” -> Y
        • “ KEY” -> List<Value>
        • @ReadThroughAssignCache
      • 1-to-1, 1-to-Many, Parameterized
        • Key -> Value
        • Key -> List<Value>
        • @ReadThroughSingleCache
      • Many-to-Many
        • List<Key> -> List<Value>
        • @ReadThroughMultiCache
    17. List -> List Contract
      • Requires:
        • Agree in Length
        • Agree in Sequence
      • Each Key/Value Pair is an individual cache entry
      • No Map support (yet?)
      • Subset Pass-Through
    18. RTM - Example
      • @ReadThroughMultiCache(
      • keyIndex = 0,
      • namespace = &quot;VETS&quot;,
      • expiration = 300)
      • List<Vet> getVet(List<Long> ids) {
      • ...
      • }
    19. Pseudocode of Invalidate Scenario
      • $key = calculateValueCacheName()
      • doUnderlyingOperations()
      • deleteFromCache($key)
      • Removes info from the cache
    20. IAC – Example
      • @InvalidateAssignCache(
      • assignedKey = &quot;InTheWindow&quot;,
      • namespace = &quot;DOG&quot;)
      • void removeFromWindow(Dog dog) {
      • ...
      • }
    21. ISC – Example
      • @InvalidateSingleCache(
      • keyIndex = 0,
      • namespace = &quot;FISH&quot;)
      • void died(Fish fish) {
      • ...
      • }
    22. IMC – Example
      • @InvalidateMultiCache(
      • keyIndex = 1,
      • namespace = &quot;DOG&quot;)
      • void sellLitter(Buyer to, List<Dog> dogs) {
      • ...
      • }
    23. Pseudocode for Update Scenario
      • doUnderlyingOperations()
      • $key = calculateValueCacheName()
      • $value = harnessValueToStore()
      • storeInCache($key, $value)
      • Puts info into the cache
    24. UAC - Example
      • @UpdateAssignCache(
      • assignedKey = &quot;InTheWindow&quot;,
      • dataIndex = -1,
      • namespace = &quot;DOG&quot;,
      • expiration = 300)
      • Dog chooseDogForWindow() {
      • ...
      • }
    25. USC - Example
      • @UpdateSingleCache(
      • keyIndex = 0,
      • dataIndex = 0,
      • namespace = &quot;FISH&quot;,
      • expiration = 300)
      • void addToInventory(Fish fish) {
      • ...
      • }
    26. UMC - Example
      • @UpdateMultiCache(
      • keyIndex = 2,
      • dataIndex = -1,
      • namespace = &quot;DOG&quot;,
      • expiration = 300)
      • List<Dog> newLitter(Dog mom, Dog dad, List<Long> ids) {
      • ...
      • }
    27. DEMO
      • DEMO...
      • Demo...
      • Demo...
      • Demo.
    28. Protection from Exceptions
      • Exceptions from (your) underlying code should flow as normal
      • Exceptions within the caching code should be invisible to user, other than via log
      • Commons-logging / Log4J
    29. Best Practices
      • Externalizable (!!!)
        • Up to 8x faster!?!
      • Single Canonical Representation
        • How to do aggregate collections
      • Invalidates on Delete
      • Updates on Save
    30. What SSM Doesn't Do
      • Stampede Protection or Soft Locks
      • Namespace Invalidation
      • Multi-Invalidation / Method
      • Multi-Parameter Keys
    31. Possible Future Features
      • Multiple Logical Memcacheds
      • Cache Observers
      • Second-level cache
    32. Version 2.0 Changes
      • Package Structure
      • Remove Index Params, Adopt Annotations
        • -1 -> @ReturnValueKeyProvider
        • 0+ -> @ParameterValueKeyProvider
      • Key Calculation
        • Spring Bean Nameable
        • @ReturnValueKeyProvider(
        • keyProviderBeanName = “myBeanName”
        • )
    33. Other Projects to Know About
      • Statsproxy - Monitoring
        • Supported by Gear6
      • Brutis - Benchmarking
        • Also by Gear6
      • Xmemcached
        • Young
      • Whalin
        • Old, Stable
        • Not Maintained?
    34.  
    35. Presentation and Demo Files
      • Blog Post: http://nelz.net/2009/10/02/ssm-at-svcc/
      • On Project Page:
        • http://code.google.com/p/simple-spring-memcached/
      • Presentation
      • Demo Code
      • Also on SlideShare
      • Gliffy.com
    36. Photo Credits
      • http://www.flickr.com/photos/adulau/3086751588/
      • http://www.flickr.com/photos/edrabbit/3440426582/
      • http://www.flickr.com/photos/nielsvk/258851215/
      • http://www.flickr.com/photos/origomi/22442743/
      • http://www.flickr.com/photos/samcrockett/2213593924/
      • http://www.flickr.com/photos/themarkpike/83868756/
      • http://www.flickr.com/photos/bohman/210977249/
      • http://www.flickr.com/photos/red5standingby/235794106/
      • http://www.flickr.com/photos/roblee/375671072/
      • http://www.flickr.com/photos/andyandorla/239043213/
      • http://www.flickr.com/photos/chrisdag/1225937650/
      • http://www.flickr.com/photos/mechanikat/2727944748/
      • http://www.flickr.com/photos/expressmonorail/3694867130/
      • http://www.flickr.com/photos/ttstam/3833225072/
      • http://www.flickr.com/photos/vernhart/1574355240/
    37. Questions Questions?
    SlideShare Zeitgeist 2009

    + nelz9999nelz9999 Nominate

    custom

    291 views, 1 favs, 0 embeds more stats

    This is the presentation I will be giving on Sunday more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 291
      • 291 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 9
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories