Caching strategies with lucee

62
Lucee Caching Strategies Gert Franz Rasia GmbH

Transcript of Caching strategies with lucee

Page 1: Caching strategies with lucee

Lucee Caching Strategies

Gert FranzRasia GmbH

Page 2: Caching strategies with lucee

WHO AM I?

• Gert Franz– Involved with Lucee and Railo since day 1

– Into CFML for 17 years

– DBA, System architect

– CFML Passionate

• Rasia is founding Member of theLucee Association

Page 3: Caching strategies with lucee

MY EVOLUTION

Assembler Basic Clipper Pascal Delphi Java CFML Lucee

Page 4: Caching strategies with lucee

WHO AM I?

• Studied Astrophysics in Munich

• Basic, dBase, Clipper, Visual Basic, Delphi, Java

• Performance, DB & Code Tuning is my professional Hobby

• I live in Switzerland

• Lucee training, consulting, support etc.

Page 5: Caching strategies with lucee
Page 6: Caching strategies with lucee
Page 7: Caching strategies with lucee

WHY?

• Many server side operations are time consuming– Database, function calls, CFCs, CFHTTP, web services– "It works on my machine" effect– Tons of traffic make it necessary

Page 8: Caching strategies with lucee

So clearly

Caching makes sense

Page 9: Caching strategies with lucee

CACHING UPS AND DOWNS

• Pro’s– Well yes, can’t really get faster than that

– Mostly depends on the storage mechanism

– Obviously RAM is the best location

Page 10: Caching strategies with lucee

CACHING UPS AND DOWNS

• Con’s

– Well the only downside is the topicality / relevanceof the data.

Page 11: Caching strategies with lucee

OK GOT IT, CFML HOW, WHAT?

• Your server is the clerk

• It waits for requests

• It checks places to retreive information

• It takes time to do so

Page 12: Caching strategies with lucee

SO HOW DOES THIS LOOK LIKE

Page 13: Caching strategies with lucee
Page 14: Caching strategies with lucee

CACHES DRIVERS

• Cache in Lucee is an interface what andwhere can I cache

• Drivers are how you can store the data cached

Page 15: Caching strategies with lucee
Page 16: Caching strategies with lucee

AVAILABLE CACHES

• PagePool

• Object

• Template

• Function

• Include

• HTTP

• Query

• Webservice

• File

• Other

Page 17: Caching strategies with lucee
Page 18: Caching strategies with lucee

AVAILABLE DRIVERS

• RAM

• EHCache

• EHCache Remote

• Mongo DB

• Redis

• Couchbase *

• Memcached

• Database

• Infinispan

Page 19: Caching strategies with lucee
Page 20: Caching strategies with lucee

PAGEPOOL CACHE

• Used whenever Lucee is supposed to execute a .cfm file

• Choose between never, once and always

• Data in cache can be listed (pagePoolList())

• Data can be cleared (pagePoolClear())

• Can not be used with a driver

Page 21: Caching strategies with lucee

PAGEPOOL CACHE

Page 22: Caching strategies with lucee
Page 23: Caching strategies with lucee

OBJECT CACHE

• Cache used with cacheGet() cachePut() etc.

• Is also used with the tag cfcache actionget/put

• Can be used with any driver

Page 24: Caching strategies with lucee
Page 25: Caching strategies with lucee

TEMPLATE CACHE

• Cache used with tag cfcache actions

– Content

– Cache

– serverCache

• Can be used with any driver

Page 26: Caching strategies with lucee
Page 27: Caching strategies with lucee

FUNCTION CACHE

• You can use the attribute cachedwithin forfunctions

• Deterministic functions can be cached

• Function will NOT be executed,

• return value will be returned and content will be generated

• Can be stored with any driver

Page 28: Caching strategies with lucee

FUNCTION CACHE EXAMPLE

struct function calcEnvironment(required string sUserAgent)

cachedWithin="0.1" {

some regexp stuff

some db stuff

return stEnv;

}

Page 29: Caching strategies with lucee
Page 30: Caching strategies with lucee

INCLUDE CACHE

• I guess we were smoking pot when wedesigned this

• Includes can be cached. Prevents executionand cached content will be rendered(functionality is IMHO incomplete)

• Can be stored with any driver

Page 31: Caching strategies with lucee

FUNCTION CACHE EXAMPLE

include "myFile.cfm" cachedWithin="0.1";

Page 32: Caching strategies with lucee
Page 33: Caching strategies with lucee

HTTP CACHE

• The implementation is quite useful sinceCFHTTP calls are very time consuming

• Just add the cachedwithin attribute to it

• It will cache the CFHTTP.fileContent

• Can be stored with any driver

Page 34: Caching strategies with lucee

FUNCTION CACHE EXAMPLE

http url="http://www.google.com" cachedWithin="0.1";

Page 35: Caching strategies with lucee
Page 36: Caching strategies with lucee

WEBSERVICE CACHE

• Is a new type of cache which allows you tocache web services

• Just add cachedwithin to the cfinvoke call

• Can be stored with any driver

Page 37: Caching strategies with lucee
Page 38: Caching strategies with lucee

FILE CACHE

• Is a new type of cache which allows you tocache file actions

• Just add cachedwithin to the cffile call

• In addition the file functions allow theargument as well

• Can be stored with any driver

Page 39: Caching strategies with lucee
Page 40: Caching strategies with lucee

HONORABLE MENTIONS

Page 41: Caching strategies with lucee
Page 42: Caching strategies with lucee

QUERY CACHE

• For sure the most used caching feature

• Uses the sql, the params and the datasourceas keys

• Can be stored with any driver

Page 43: Caching strategies with lucee

QUERY CACHE EXAMPLE

qRet = queryExecute(

sql:"SELECT TOP 10 name, zip FROM customers",

options: {

cachedWithin:0.1

datasource:"test",

tags: ["Test1", "Test2"]

}

);

Page 44: Caching strategies with lucee

QUERY CACHE EXAMPLE

objectCache action="clear" tags="Test1";

Page 45: Caching strategies with lucee

QUERY CACHE UNDER THE HOOD

• Lucee stores the result of the query in thecache

• It creates a hash of the SQL, the params andthe other attributes

• When the time is up, the cached element will be removed from cache

Page 46: Caching strategies with lucee

QUERY CACHE UNDER THE HOOD

• When the query is reexecuted Lucee will return a pointer to the cached query

• It will always be a pointer to the query

UNLESS…?

Page 47: Caching strategies with lucee
Page 48: Caching strategies with lucee

CACHING UNDER LOAD

• Caching often helps solving performance problems

Page 49: Caching strategies with lucee
Page 50: Caching strategies with lucee

THE PROBLEM UNDER LOAD

• Do you really know how the application is used• Without tons of logging• Without DB profiler turned on• Without Application monitoring• Without accumulation of data

?

Page 51: Caching strategies with lucee
Page 52: Caching strategies with lucee

LEGACY APPLICATIONS

• Old, not perfectly maintained• Take a lot of time to investigate (Missing

knowledge)• Perhaps not worth rewriting• Old developer perhaps not available• Memory hog• Complex and large• Hard to tune Expensive to tune

Page 53: Caching strategies with lucee
Page 54: Caching strategies with lucee

HOW TO TUNE A LEGACY

APPLICATION

• Invest many resources

• Build up knowledge

• Have an expert look at the code

• Rewrite the whole app

• In short it is expensive

Page 55: Caching strategies with lucee

ARGUSCACHE

The best way to speed up your apps

Page 56: Caching strategies with lucee

• Designed for existing applications

• Analyzes the application behavior

• Analyzes the resources used

• Runs in the background

Here comes ARGUSCACHE

Page 57: Caching strategies with lucee

• Allows you to see what's going on

• Shows you whether you have potentioal for optimization

• Shows you the potential performance gain

ARGUSCACHE dashboard

Page 58: Caching strategies with lucee

The dashboard

Page 59: Caching strategies with lucee

• Running in the cloud

• Handling clusters

• Handling many web contexts

• Nice dashboard to manage everything

Current development

Page 60: Caching strategies with lucee

• 99.- US$ / month per context

• CFCamp Promo for early signups andtesters

• Site licence available

• Higher Discounts for support contractcustomers

Pricing

Page 61: Caching strategies with lucee
Page 62: Caching strategies with lucee

TALK TO ME / US

• Come see me or Micha at the Lucee booth

• Contact us [email protected], [email protected]

• Challenge your application

• Get highly dicounted license of ArgusCache