jsr 107 caching standard

44
1 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Upload: oracle-fusion-middleware

Post on 29-Nov-2014

6.659 views

Category:

Technology


3 download

DESCRIPTION

This presentation explain the new feature of JSR 107 Caching Standards.

TRANSCRIPT

Page 1: JSR 107 Caching Standard

1 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Page 2: JSR 107 Caching Standard

2 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

The New JSR-107 Caching Standard

レッドハット株式会社 木村 貴由 日本オラクル株式会社 寺田 佳央

Page 3: JSR 107 Caching Standard

3 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

以下の事項は、弊社の一般的な製品の方向性に関する概要を説明するものです。また、情報提供を唯一の目的とするものであり、いかなる契約にも組み込むことはできません。以下の事項は、マテリアルやコード、機能を提供することをコミットメント(確約)するものではないため、購買決定を行う際の判断材料になさらないで下さい。オラクル製品に関して記載されている機能の開発、リリースおよび時期については、弊社の裁量により決定されます。

OracleとJavaは、Oracle Corporation 及びその子会社、関連会社の米国及びその他の国における登録商標です。文中の社名、商品名等は各社の商標または登録商標である場合があります。

Page 4: JSR 107 Caching Standard

4 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Program Agenda

• はじめに •  JSR-107 Caching の概要 •  JSR-107 Caching の詳細

Page 5: JSR 107 Caching Standard

5 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8 5

はじめに

Page 6: JSR 107 Caching Standard

6 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Page 7: JSR 107 Caching Standard

7 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Page 8: JSR 107 Caching Standard

8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Page 9: JSR 107 Caching Standard

9 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Page 10: JSR 107 Caching Standard

10 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Page 11: JSR 107 Caching Standard

11 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Page 12: JSR 107 Caching Standard

12 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Page 13: JSR 107 Caching Standard

13 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8 5

JSR-107 の概要

Page 14: JSR 107 Caching Standard

14 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

仕様に関する情報入手先

http://jcp.org/en/jsr/detail?id=107

Page 15: JSR 107 Caching Standard

15 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

http://tinyurl.com/7b5tenh

https://github.com/jsr107

仕様に関する情報入手先

Page 16: JSR 107 Caching Standard

16 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

ConcurrentMapに類似

putIfAbsent() remove() replace() など

Page 17: JSR 107 Caching Standard

17 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

どの位のサイズ?

Page 18: JSR 107 Caching Standard

18 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

http://tinyurl.com/7nkqzxc

Java SE/EE 何れの環境でも利用可能

※ Java SE 6/EE 6 以降

Page 19: JSR 107 Caching Standard

19 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

 <dependency>!   <groupId> javax.cache </groupId>!   <artifactId> cache-api </artifactId>!   <version> 0.5 </version> ← (2012/03/13 リリース)! </dependency>

スタート・ポイント

Page 20: JSR 107 Caching Standard

20 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Map に対する Cache の利点

• Atomic オペレーション (java.util.ConcurrentMapと類似) • Read-through キャッシュ • Write-through キャッシュ • ライフサイクル • キャッシュ・イベントリスナー • 統計情報

Page 21: JSR 107 Caching Standard

21 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

オプションの機能

• トランザクション処理 (isolationレベルの指定) • アノテーション (Spring/CDI) •  storeByReference (デフォルト storeByValue)

Page 22: JSR 107 Caching Standard

22 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

主要なAPI

• CacheManager – キャッシュの検索、ライフサイクル管理など – すべてのキャッシュは CacheManager に含まれる – クラスタ環境では CacheMnagerがクラスタ化される

• CacheBuilder – 該当する CacheManager から Cacheを生成 – Cache に関する各種追加設定が可能

• 有効期限設定、統計情報の有効・無効、トランザクションの有効・無効

Page 23: JSR 107 Caching Standard

23 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

主要なAPI

• Cache – キャッシュ操作用のメソッドを提供 –  containsKey, get, getAll, getAndPut, getAndRemove, getAndReplace, getCacheManager, getConfiguration, getMBean, getName, getStatistics, invokeEntryProcess, iterator, load, loadAll, put, putAll, putifAbsent, registerCacheEntryListener, remove, removeAll, replace, unregisterCacheEntryListener, unwrap

Page 24: JSR 107 Caching Standard

24 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

キャッシュのサンプル・コード String cacheName = "sampleCache";! CacheManager cacheManager = Caching.getCacheManager();! Cache<Integer, Date> cache = cacheManager.getCache(cacheName);!! if (cache == null) {! cache = cacheManager.! <Integer,Date>createCacheBuilder(cacheName).build();! }! Date value1 = new Date();! Integer key = 1;! cache.put(key, value1);! Date value2 = cache.get(key);!

Page 25: JSR 107 Caching Standard

25 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8 5

JSR-107 の詳細

Page 26: JSR 107 Caching Standard

26 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

キャッシュのイベント機構

• CacheEntryCreatedListener • CacheEntryRemovedListener • CacheEntryReadListener • CacheEntryUpdatedListener • CacheEntryExpiredListener

Page 27: JSR 107 Caching Standard

27 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

キャッシュのイベント機構

• CacheEntryEvent – Cache getSource() – K getKey() – V getValue()

Page 28: JSR 107 Caching Standard

28 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

アノテーション

• @CacheResult • @CachePut • @CacheRemoveEntry • @CacheRemoveAll

Page 29: JSR 107 Caching Standard

29 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

アノテーションを使用しない場合

private Cache<Long, User> cache; !! public User findUser(long id){!   User user = cache.get(id);!   if ( user == null ) {!     user = …; // DB から指定された ID を元に検索!     cache.put(id, user); //キャッシュに ID と User を登録!   }!   return user;! }!

Page 30: JSR 107 Caching Standard

30 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

アノテーションを使用する場合

• キャッシュに存在しない場合 – メソッド内部処理を実行し実行結果をキャッシュ

• キャッシュに存在した場合 – メソッドの内部は実行せずキャッシュの内容を返す

@CacheResult(cacheName=”foo-cache")! public User findUser(long id) {!   User user = …; //DB から指定された ID を元に検索!   return user;! }!

Page 31: JSR 107 Caching Standard

31 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

ビジネスロジックへの適用例 @CacheDefaults(cacheName="blogManager")!

public class BlogManager {!

@CacheResult!

public Blog getBlogEntry(String title) {...}!

@CachePut!

public void createEntry(@CacheKeyParam String title,!

@CacheValue Blog blog) {...}!

@CacheRemoveEntry!

public void removeBlogEntry(String title) {...}!

@CacheRemoveAll!

public void removeAllBlogs() {...}!

}

Page 32: JSR 107 Caching Standard

32 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

トランザクション

• トランザクショナルリソースのキャッシュ • データベース更新のシナリオ

– データベース更新 – キャッシュ更新 – データベースコミット失敗!

• キャッシュとキャッシュ対象の同期が必要

Page 33: JSR 107 Caching Standard

33 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8 5

デモ

Page 34: JSR 107 Caching Standard

34 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

@Named!

@RequestScoped!

public class Eetter {!

   @Inject!

   private TwitterService twitter;!

   private String query;!

   private List<Tweet> tweets;!

   private long searchTimeTaken;!

……続く!

Twitter検索結果のキャッシュ(CDI)

Page 35: JSR 107 Caching Standard

35 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

@Named!

@RequestScoped!

public class Eetter {!

  ……(続き)!

   public void search() throws Exception {!

       long begin = System.currentTimeMillis();!

       tweets = twitter.search(query);!

       searchTimeTaken = !

System.currentTimeMillis() - begin;!

   }}!

}

Twitter検索結果のキャッシュ(CDI)

Page 36: JSR 107 Caching Standard

36 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

@CacheDefaults(cacheName="twitter")!

public class TwitterService {!

   @CacheResult!

   public List<Tweet> search(String queryString) !

throws TwitterException {!

       List<Tweet> tweets = ...; // Twitter検索を実行        return tweets;!

   }!

……続く

キャッシュ用のアノテーション実装例

Page 37: JSR 107 Caching Standard

37 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

   ……続き!

  @CacheRemoveEntry!

   public void removeCache(String queryString) { }!

!

   @CacheRemoveAll!

   public void clearCache() { }!

}

Twitter検索結果のキャッシュ(アノテーション)

Page 38: JSR 107 Caching Standard

38 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8 5

まとめ

Page 39: JSR 107 Caching Standard

39 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

想定する各社の実装製品 •  Terracotta - Ehcache •  JBoss ‒ Infinispan • Oracle - Coherence •  IBM ‒ WebSphere eXtreme Scale •  SpringSource - Gemfire • GridGain • Google App Engine - memcache • その他

Page 40: JSR 107 Caching Standard

40 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

まとめ

•  JSR 107 : JCACHE - Java Temporary Caching API –  Java オブジェクトのキャッシュ –  Java アプリケーションの高速化を実現 – 高いスケーラビリティ – DB キャッシュ以外の様々な場面で利用可能 – ConcurrentMap のように簡単な操作性

Page 41: JSR 107 Caching Standard

41 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

参考情報

•  JSR 107 –  http://jcp.org/en/jsr/detail?id=107

•  Early Draft 仕様 –  http://tinyurl.com/7b5tenh

• ソースコード –  https://github.com/jsr107

• スペックリード:Greg Luck のブログ –  http://gregluck.com/blog

Page 42: JSR 107 Caching Standard

42 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Russia 17–18 April 2012

India 3–4 May 2012

San Francisco September 30–October 4, 2012

Page 43: JSR 107 Caching Standard

43 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8

Page 44: JSR 107 Caching Standard

44 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8