caching strategies with lucee
Post on 21-Jan-2018
151 Views
Preview:
TRANSCRIPT
Lucee Caching Strategies
Gert FranzRasia GmbH
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
MY EVOLUTION
Assembler Basic Clipper Pascal Delphi Java CFML 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.
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
So clearly
Caching makes sense
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
CACHING UPS AND DOWNS
• Con’s
– Well the only downside is the topicality / relevanceof the data.
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
SO HOW DOES THIS LOOK LIKE
CACHES DRIVERS
• Cache in Lucee is an interface what andwhere can I cache
• Drivers are how you can store the data cached
AVAILABLE CACHES
• PagePool
• Object
• Template
• Function
• Include
• HTTP
• Query
• Webservice
• File
• Other
AVAILABLE DRIVERS
• RAM
• EHCache
• EHCache Remote
• Mongo DB
• Redis
• Couchbase *
• Memcached
• Database
• Infinispan
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
PAGEPOOL CACHE
OBJECT CACHE
• Cache used with cacheGet() cachePut() etc.
• Is also used with the tag cfcache actionget/put
• Can be used with any driver
TEMPLATE CACHE
• Cache used with tag cfcache actions
– Content
– Cache
– serverCache
• Can be used with any driver
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
FUNCTION CACHE EXAMPLE
struct function calcEnvironment(required string sUserAgent)
cachedWithin="0.1" {
some regexp stuff
some db stuff
return stEnv;
}
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
FUNCTION CACHE EXAMPLE
include "myFile.cfm" cachedWithin="0.1";
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
FUNCTION CACHE EXAMPLE
http url="http://www.google.com" cachedWithin="0.1";
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
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
HONORABLE MENTIONS
QUERY CACHE
• For sure the most used caching feature
• Uses the sql, the params and the datasourceas keys
• Can be stored with any driver
QUERY CACHE EXAMPLE
qRet = queryExecute(
sql:"SELECT TOP 10 name, zip FROM customers",
options: {
cachedWithin:0.1
datasource:"test",
tags: ["Test1", "Test2"]
}
);
QUERY CACHE EXAMPLE
objectCache action="clear" tags="Test1";
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
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…?
CACHING UNDER LOAD
• Caching often helps solving performance problems
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
?
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
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
ARGUSCACHE
The best way to speed up your apps
• Designed for existing applications
• Analyzes the application behavior
• Analyzes the resources used
• Runs in the background
Here comes ARGUSCACHE
• Allows you to see what's going on
• Shows you whether you have potentioal for optimization
• Shows you the potential performance gain
ARGUSCACHE dashboard
The dashboard
• Running in the cloud
• Handling clusters
• Handling many web contexts
• Nice dashboard to manage everything
Current development
• 99.- US$ / month per context
• CFCamp Promo for early signups andtesters
• Site licence available
• Higher Discounts for support contractcustomers
Pricing
TALK TO ME / US
• Come see me or Micha at the Lucee booth
• Contact us gert@rasia.ch, michael@rasia.ch
• Challenge your application
• Get highly dicounted license of ArgusCache
top related