20
Talk about ``Active’’ Cache by qrtt1

idea: talk about the Active Cache

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: idea: talk about the Active Cache

Talk about ``Active’’ Cache

by qrtt1

Page 2: idea: talk about the Active Cache

Cache For Web Application

http request

Web Handler Layer

Page 3: idea: talk about the Active Cache

Cache For Web Application

http request

Web Handler Layer

Business Logic Layer

call some business logic

Page 4: idea: talk about the Active Cache

Cache For Web Application

http request

Web Handler Layer

Business Logic Layer

call some business logic

very very busy business

Page 5: idea: talk about the Active Cache

Cache For Web Application

http request

Web Handler Layer

Business Logic Layer

call some business logic

http response

compose the final output

very very busy business

Page 6: idea: talk about the Active Cache

Cache For Web Application

http request

Web Handler Layer

Business Logic Layer

call some business logic

http response

compose the final output

very very busy business

HOW LONG DOESTHE CLIENT WAIT ?

Page 7: idea: talk about the Active Cache

Cache For Web Application

http request

Web Handler Layer

Business Logic Layer

http response

Cache Layerusing cache to reduce the response time

Page 8: idea: talk about the Active Cache

Cache For Web Application

http request

Web Handler Layer

Business Logic Layer

http response

Cache LayerHIT CACHE

Page 9: idea: talk about the Active Cache

Cache For Web Application

http request

Web Handler Layer

Business Logic Layer

http response

Cache LayerMISS CACHE

RUN IN THE BUSY WAY

Page 10: idea: talk about the Active Cache

Cache Layer

Cache is passive and only update by caller

if foo in cache: return cache[foo] data = business(xyz)cache[foo] = datareturn data

Page 11: idea: talk about the Active Cache

Cache Layer

Data in the cache is expired eventually.

if foo in cache: return cache[foo]else: # users should wait the data available

do_something_with_expired..

Page 12: idea: talk about the Active Cache

ACTIVE Cache Layer

Data in the cache is updated eventually.

if foo in active_cache: return active_cache[foo]

data = active_cache({business, xyz})return data

Page 13: idea: talk about the Active Cache

The difference

Passive Cache

put the data into cache

update the data by caller

Active Cache

put the update-method into cache

update the data by itself

Page 14: idea: talk about the Active Cache

ACTIVE Cache Layer

POC in Java Web

Using AspectJ add the advice to Business Logic

foo(a, b, c, ...)

Business Logic Layer

waving the aop-advice learning how to invoke the business logic by keep the information about {instance, method signature and arguments}

HIT CACHE forever

refresh cache data automatically

Page 15: idea: talk about the Active Cache

Active Cache Problem

How does the key to define ?

key(args of method) or ...

How to design the cache updater and scheduler ?

How to migrate the broken deserialiazation from the class definition change ?

Page 16: idea: talk about the Active Cache

Cache Key BuildingmethodA(userInfo, str, int, otherPojo)

what does a user see ? it depends on

userInfohow does data filter or

sort ?

key = signauure_ + args[0] + args[1] + args[...]

=> signature_UserInfo@a3a4a3a5_3_{a:3,b:3_}wtf, the key is so bad and never hit cache

Page 17: idea: talk about the Active Cache

Cache Key Building=> signature_UserInfo@a3a4a3a5_3_{a:3,b:3_}

sometimes toString() is a not good enoughtreat userInfo as userInfo.getGroupId()

or convert to the better key format

=> signature_1234567890_3_{a:3,b:3_}

Page 18: idea: talk about the Active Cache

Cache Key Building=> signature_OtherClass@a3a4a3a5_3_{a:3,b:3_}

sometimes OtherClass no available gettersthe useful information is assigned by its constructor

using AOP & mix-in ActiveCacheToString interfaceto provide alternative toString()

Page 19: idea: talk about the Active Cache

Should I update it

request from Http Client should not update

request from Scheduler should update

How to check the issue coming from ?

check the stacktrace having javax.servlet.http.HttpServlet.service is request from Http Client.

Page 20: idea: talk about the Active Cache

Handle the class definition change

class definition changes will break everything when deserialization

should change the cache storage pool, too

DevOps should support to check the change happening