Talk about ``Active’’ Cache
by qrtt1
Cache For Web Application
http request
Web Handler Layer
Cache For Web Application
http request
Web Handler Layer
Business Logic Layer
call some business logic
Cache For Web Application
http request
Web Handler Layer
Business Logic Layer
call some business logic
very very busy business
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
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 DOES
THE CLIENT WAIT ?
Cache For Web Application
http request
Web Handler Layer
Business Logic Layer
http response
Cache Layer
using cacheto reduce the response time
Cache For Web Application
http request
Web Handler Layer
Business Logic Layer
http response
Cache Layer
HIT CACHE
Cache For Web Application
http request
Web Handler Layer
Business Logic Layer
http response
Cache Layer
MISS CACHE
RUN IN THE BUSY WAY
Cache Layer
Cache is passive and only update by caller
if foo in cache:
return cache[foo]
data = business(xyz)
cache[foo] = data
return data
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..
ACTIVECache Layer
Data in the cache is updated eventually.
if foo in active_cache:
return active_cache[foo]
data = active_cache({business, xyz})
return data
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
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
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 ?
Cache Key Building
methodA(userInfo, str, int, otherPojo)
what does a user
see ? it depends on
userInfo
how 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
Cache Key Building
=> signature_UserInfo@a3a4a3a5_3_{a:3,b:3_}
sometimes toString() is a not good enough
treat userInfo as userInfo.getGroupId()
or convert to the better key format
=> signature_1234567890_3_{a:3,b:3_}
Cache Key Building
=> signature_OtherClass@a3a4a3a5_3_{a:3,b:3_}
sometimes OtherClass no available getters
the useful information is assigned by its constructor
using AOP & mix-in ActiveCacheToString interface
to provide alternative toString()
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.
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

idea: talk about the Active Cache

  • 1.
  • 2.
    Cache For WebApplication http request Web Handler Layer
  • 3.
    Cache For WebApplication http request Web Handler Layer Business Logic Layer call some business logic
  • 4.
    Cache For WebApplication http request Web Handler Layer Business Logic Layer call some business logic very very busy business
  • 5.
    Cache For WebApplication http request Web Handler Layer Business Logic Layer call some business logic http response compose the final output very very busy business
  • 6.
    Cache For WebApplication http request Web Handler Layer Business Logic Layer call some business logic http response compose the final output very very busy business HOW LONG DOES THE CLIENT WAIT ?
  • 7.
    Cache For WebApplication http request Web Handler Layer Business Logic Layer http response Cache Layer using cacheto reduce the response time
  • 8.
    Cache For WebApplication http request Web Handler Layer Business Logic Layer http response Cache Layer HIT CACHE
  • 9.
    Cache For WebApplication http request Web Handler Layer Business Logic Layer http response Cache Layer MISS CACHE RUN IN THE BUSY WAY
  • 10.
    Cache Layer Cache ispassive and only update by caller if foo in cache: return cache[foo] data = business(xyz) cache[foo] = data return data
  • 11.
    Cache Layer Data inthe cache is expired eventually. if foo in cache: return cache[foo] else: # users should wait the data available do_something_with_expired..
  • 12.
    ACTIVECache Layer Data inthe cache is updated eventually. if foo in active_cache: return active_cache[foo] data = active_cache({business, xyz}) return data
  • 13.
    The difference Passive Cache putthe data into cache update the data by caller Active Cache put the update-method into cache update the data by itself
  • 14.
    ACTIVE Cache Layer POCin 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
  • 15.
    Active Cache Problem Howdoes 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 ?
  • 16.
    Cache Key Building methodA(userInfo,str, int, otherPojo) what does a user see ? it depends on userInfo how 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
  • 17.
    Cache Key Building =>signature_UserInfo@a3a4a3a5_3_{a:3,b:3_} sometimes toString() is a not good enough treat userInfo as userInfo.getGroupId() or convert to the better key format => signature_1234567890_3_{a:3,b:3_}
  • 18.
    Cache Key Building =>signature_OtherClass@a3a4a3a5_3_{a:3,b:3_} sometimes OtherClass no available getters the useful information is assigned by its constructor using AOP & mix-in ActiveCacheToString interface to provide alternative toString()
  • 19.
    Should I updateit 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.
  • 20.
    Handle the classdefinition change class definition changes will break everything when deserialization should change the cache storage pool, too DevOps should support to check the change happening