Advance Caching Techniques - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

Advance Caching Techniques

Description:

SQL statements must be exactly the same this includes even tabbing ... SELECT * (Note: tabbing) FROM us_states. ORDER BY State /cfquery ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 32
Provided by: keenh
Category:

less

Transcript and Presenter's Notes

Title: Advance Caching Techniques


1
Advance Caching Techniques
SCCFUG Winter 2002 Conference
  • Keen Haynes
  • MKAD
  • khaynes_at_mkad.com

2
Introduction
  • What is caching?
  • Why is it important to me?
  • What can I cache?
  • How do I leverage caching

3
Introduction (cont.)
  • Template Cache
  • Trusted Cache
  • Database Connection Cache or Pooling
  • Query Caching

4
Template Cache
  • Cache the HTML generated by a template
  • Cache for a specified period
  • Caching can be client-side, server-side or both

5
ltCFCACHEgt
  • Speeds up page rendering when dynamic content
    does not have to be retrieved each time a user
    accesses the page. To accomplish this, cfcache
    creates temporary files that contain the static
    HTML returned from a ColdFusion page.

6
ltCFCACHEgt (cont.)
  • ltcfcache
  • action "cache" or "flush" or "clientCache" or
    "optimal"
  • username "username"
  • password "password"
  • protocol "protocol name"
  • timeout timeout date-time"
  • directory "directory name for map file"
  • cacheDirectory directory name for cached
    pages"
  • expireURL "wildcarded URL reference"
  • port "port-number"gt

7
ltCFCACHEgt (cont.)
  • Client-side caching
  • ltCFCACHE ACTIONCLIENTCACHE
  • Server-side caching
  • ltCFCACHE ACTIONCACHE
  • Optimal combination of client server
  • ltCFCACHE ACTIONOPTIMAL
  • Refresh a cached page
  • ltCFCACHE ACTIONFLUSH

8
ltCFCACHEgt (cont.)
  • ltCFCACHE ACTIONCACHE
  • TIMEOUTDateAdd(h, -4, Now())gt
  • ltCFCACHE ACTIONFLUSH
  • EXPIREURLCustomer.cfm?

9
Trusted Cache
  • When checked, any requested files found to
    currently reside in the template cache will not
    be inspected for potential updates recommended
    for sites that do not update during the life of
    the server.

10
Trusted Cache (cont.)
  • Refreshing the template cache
  • Uncheck the 'Trusted Cache' option in the
    ColdFusion Administrator.
  • Click Apply.
  • Check the "Trusted Cache" option.
  • Click Apply.

11
Caching and CF Admin
12
Database Connection Caching
  • If "Maintain Database Connections" is enabled for
    a data source, CF keeps the connection open after
    its first connection to the database. It does not
    log out of the database after this first
    connection.
  • Will create a new connection if a request is
    using a data source connection that is already
    opened, and another request is received
  • The connection pool can increase up to the
    setting for simultaneous connections limit which
    is set for each data source.

13
Database Connection Caching (cont.)
14
Caching and database queries
  • What does ColdFusion do when it sees a query?
  • ltCFQUERYgt
  • Cachedwithin
  • Cachedafter

15
Caching and database queries (cont)
  • What does ColdFusion do when it sees a
  • query?
  • Passes SQL content to appropriate driver (handled
    by a thread)
  • Waits for results to return before processing
    rest of tag
  • Will use existing instance of driver if data
    source already in use
  • Will cache connection information if Maintain
    Database Connections is selected

16
Caching and database queries (cont)
  • ltCFQUERY NameStates DATASOURCEtest
  • CACHEDWITHINCreateTimeSpan(0,1,0,0)gt
  • SELECT state_name FROM tbl_state
  • lt/CFQUERYgt
  • CACHEDWITHIN (TIMESPAN) caches the query
    results for a specified time
  • CACHEDAFTER (DATE) caches the query based on a
    particular date and time

17
Caching and database queries (cont)
  • ltCFQUERY Nameus_states DATASOURCEStates
  • SELECT
  • FROM us_states
  • ORDER BY State
  • lt/CFQUERYgt

18
Caching and database queries (cont)
  • ltCFQUERY Nameus_states DATASOURCEStates
  • CACHEDWITHINCreateTimeSpan(0,1,0,0)gt
  • SELECT
  • FROM us_states
  • ORDER BY State
  • lt/CFQUERYgt

19
Caching and database queries (cont)
  • Points to remember
  • Queries are cached on a server-wide basis
  • Documentation states query must use same SQL
    statement, data source, query name, user name,
    password, and DBTYPE (I did not find this to be
    true for query name )
  • SQL statements must be exactly the same this
    includes even tabbing

20
Caching and database queries (cont)
  • ltCFQUERY NameStates DATASOURCEtest
  • CACHEDWITHINCreateTimeSpan(0,1,0,0)gt
  • SELECT state_name FROM tbl_state
  • lt/CFQUERYgt
  • IS NOT THE SAME QUERY AS
  • ltCFQUERY NameStates DATASOURCEtest2
  • CACHEDWITHINCreateTimeSpan(0,1,0,0)gt
  • SELECT state_name FROM tbl_state
  • lt/CFQUERYgt

21
Caching and database queries (cont)
  • ltCFQUERY NameStates DATASOURCEtest
  • CACHEDWITHINCreateTimeSpan(0,1,0,0)gt
  • SELECT state_name FROM tbl_state
  • lt/CFQUERYgt
  • IS NOT THE SAME QUERY AS
  • ltCFQUERY NameStates DATASOURCEtest
  • CACHEDWITHINCreateTimeSpan(0,1,0,0)gt
  • SELECT state_name
  • FROM tbl_state
  • lt/CFQUERYgt

22
Caching and database queries (cont)
  • ltcfquery name"us_states" datasource"States"
  • CACHEDWITHINCreateTimeSpan(0,1,0,0)gt
  • SELECT (Note tabbing)
  • FROM us_states
  • ORDER BY State
  • lt/cfquerygt

23
Caching and database queries (cont)
  • More points to remember
  • Queries containing dynamic values will result in
    an instance of each record setting being cached
  • Max limit of 100 cached queries was removed with
    CF4.5
  • Cached queries will not reflect changes to the
    database until the cache interval has expired.

24
Caching and database queries (cont)
  • Forcing an update of cached queries
  • This can be accomplished by following queries
    that
  • effect changes with a CFQUERY that contains a
    negative
  • CACHEDWITHIN value
  • ltCFQUERY NameCustomers DATASOURCEtest
  • CACHEDWITHINCreateTimeSpan(0,0,0,-1)gt
  • SELECT customer_name FROM tbl_customer
  • lt/CFQUERYgt

25
Caching and database queries (cont)
  • ltCFQUERY NameUpdateCustomer DATASOURCEtestgt
  • UPDATE
  • lt/CFQUERYgt
  • ltCFQUERY NameCustomers DATASOURCEtest
  • CACHEDWITHINCreateTimeSpan(0,0,0,-1)gt
  • SELECT customer_name FROM tbl_customer
  • lt/CFQUERYgt

26
Advance Security Caching and CF Admin
  • Security Server Policy Store Cache caches
    Advanced security information. By default, it is
    notified of administrative changes to the policy
    store once every minute. Using this cache
    provides the most noticeable performance
    improvements with Advanced security.
  • Security Server Authorization Cache caches each
    unique isAuthorized call.
  • ColdFusion Server Cache caches isAuthorized and
    isProtected requests.

27
Advance Security Caching and CF Admin (cont.)
28
Advance Security Caching and CF Admin (cont.)
29
ltCFOBJECTCACHEgt
  • The CFML Language Reference ommitssic a new
    ColdFusion Server 5 tag, cfobjectcache. It
    clears, or flushes, the entire query cache.
  • ltcfobjectcache action"clear"gt The action
    attribute must be set to clear. No other values
    are supported.
  • http//livedocs.macromedia.com/cf50docs/CFML_Refer
    ence/Tags78.jsp1102316

30
Summary
  • Things to consider
  • Overhead
  • Need for current information
  • Identify candidates for caching both long
    running and frequently called queries and
    templates
  • Testing to verify expected results

31
  • ltCFQUESTIONSgt
  • ?
  • lt/CFQUESTIONSgt
Write a Comment
User Comments (0)
About PowerShow.com