Edgewall Software

Changes between Version 4 and Version 5 of TracDev/CacheManager


Ignore:
Timestamp:
Feb 23, 2016, 8:20:26 PM (8 years ago)
Author:
figaro
Comment:

Cosmetic changes

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/CacheManager

    v4 v5  
    1 = Caching and cache invalidation =
     1= Caching and cache invalidation
    22
    3 Trac uses various caches at the component level, in order to speed-up costly tasks. Some examples are the ticket fields cache (#6436), others are the InterMapTxt cache, the user permission cache, the oldest example being the Wiki page cache.
     3Trac uses various caches at the component level, in order to speed-up costly tasks. Some examples are the ticket fields cache (#6436), the InterMapTxt cache, the user permission cache, and the oldest example being the Wiki page cache.
    44
    5 Those cache are held at the level of `Component` instances. For a given class, there's one such instance per environment in any given server process. The first thing to take into account here is that those caches must be safely accessed and modified when accessed by concurrent threads (in multi-threaded web front ends, that is).
     5Those caches are held at the level of `Component` instances. For a given class, there's one such instance per environment in any given server process. The first thing to take into account here is that those caches must be safely accessed and modified when accessed by concurrent threads (in multi-threaded web front ends, that is).
    66
    7 But due to the always possible concurrent access at the underlying database level by '''multiple processes''', there's also a need to maintain a consistency and up-to-date status of those caches across all processes involved. Otherwise, you might do a change by the way of one request and the next request (even the GET following a redirect after your POST!) might be handled by a different server process which has a different "view" of the application state.
     7But because of the possibility of concurrent access at the underlying database level by '''multiple processes''', there is also a need to maintain a consistency and up-to-date status of those caches across all processes involved. Otherwise, you might do a change by the way of one request and the next request (even the GET following a redirect after your POST!) might be handled by a different server process which has a different "view" of the application state.
    88
    99This doesn't even have to imply a multi-process server setup, as all what is needed is e.g. a modification of the database done using trac-admin.
    1010
    11 == The Cache Manager ==
    12 Starting with Trac [milestone:0.12] (more precisely r8071), we introduced a !CacheManager component.
    13 That component is mostly transparent to the end developer, which only has to deal with a decorator
    14 that can be used to create ''cached attributes''.
     11== The Cache Manager
     12
     13Starting with Trac [milestone:0.12] (more precisely r8071), we introduced a !CacheManager component. That component is mostly transparent to the end developer, which only has to deal with a decorator that can be used to create ''cached attributes''.
    1514
    1615 * '''Creating a cached attribute''' is done by defining a retrieval function and decorating it with the '''`@cached`''' decorator. For example, for the wiki page names:
    17 {{{
    18 #!python
     16{{{#!python
    1917@cached
    2018def pages(self, db):
     
    2624
    2725 * '''Invalidating a cached attribute''' is done by '''`del`'''eting the attribute:
    28 {{{
    29 #!python
     26{{{#!python
    3027def wiki_page_added(self, page):
    3128    if not self.has_page(page.name):
     
    4340 * The `cache` table is read the first time a cached attribute is accessed during a request. This avoids slowing down requests that don't touch cached attributes, like requests for static content for example.
    4441
    45 
    4642----
    4743See also TracDev/Proposals/CacheInvalidation for the history of the implementation details.