• Get Review Board
  • What's New
  • Products
  • Review Board Code review, image review, and document review
  • Documentation
  • Release Notes
  • Power Pack Enterprise integrations, reports, and enhanced document review
  • Try for 60 Days
  • Purchase
  • RBCommons Review Board as a Service, hosted by us
  • Pricing
  • RBTools Command line tools and Python API for Review Board
  • Documentation
  • Release Notes
  • Review Bot Automated code review, connecting tools you already use
  • Documentation
  • Release Notes
  • RB Gateway Manage Git and Mercurial repositories in your network
  • Documentation
  • Release Notes
  • Learn and Explore
  • What is Code Review?
  • Documentation
  • Frequently Asked Questions
  • Support Options
  • Third-Party Integrations
  • Demo
  • Review Board RBTools Power Pack Review Bot Djblets RB Gateway
    1. RBTools dev
    2. Version 5.x
    3. Version 4.x
    4. Version 3.x
    5. Version 2.0
    6. Version 1.0
    7. Version 0.7
    8. Version 0.6
    9. Version 0.5
    10. RBTools Python API
    11. Module and Class References
    12. rbtools.api.cache
  • Home
  • Installing RBTools
  • rbt Command
  • Configuration
  • Authenticating to Review Board
  • Repository Configuration
  • Per-User Configuration
  • Team Foundation Server Configuration
  • Commands
  • alias
  • api-get
  • attach
  • clear-cache
  • close
  • diff
  • install
  • land
  • list-repo-types
  • login
  • logout
  • patch
  • post
  • publish
  • review
  • setup-completion
  • setup-repo
  • stamp
  • status
  • status-update
  • RBTools Workflows
  • Using RBTools With Cliosoft SOS
  • Using RBTools with Git
  • Using RBTools with HCL VersionVault and IBM ClearCase
  • Using RBTools With Perforce
  • RBTools Python API
  • Overview of the Python API Client
  • Tutorial
  • Resource-Specific Functionality
  • Module and Class References
  • rbtools
  • rbtools.deprecation
  • rbtools.api
  • rbtools.api.cache
  • rbtools.api.capabilities
  • rbtools.api.client
  • rbtools.api.decode
  • rbtools.api.decorators
  • rbtools.api.errors
  • rbtools.api.factory
  • rbtools.api.request
  • rbtools.api.resource
  • rbtools.api.transport
  • rbtools.api.transport.sync
  • rbtools.api.utils
  • rbtools.clients
  • rbtools.clients.base
  • rbtools.clients.base.patch
  • rbtools.clients.base.registry
  • rbtools.clients.base.repository
  • rbtools.clients.base.scmclient
  • rbtools.clients.errors
  • rbtools.clients.bazaar
  • rbtools.clients.clearcase
  • rbtools.clients.cvs
  • rbtools.clients.git
  • rbtools.clients.mercurial
  • rbtools.clients.perforce
  • rbtools.clients.plastic
  • rbtools.clients.sos
  • rbtools.clients.svn
  • rbtools.clients.tfs
  • rbtools.config
  • rbtools.config.config
  • rbtools.config.loader
  • rbtools.diffs
  • rbtools.diffs.patches
  • rbtools.diffs.patcher
  • rbtools.diffs.tools
  • rbtools.diffs.tools.backends
  • rbtools.diffs.tools.backends.gnu
  • rbtools.diffs.tools.base
  • rbtools.diffs.tools.base.diff_file_result
  • rbtools.diffs.tools.base.diff_tool
  • rbtools.diffs.tools.errors
  • rbtools.diffs.tools.registry
  • rbtools.diffs.writers
  • rbtools.commands
  • rbtools.commands.main
  • rbtools.commands
  • rbtools.commands.base
  • rbtools.commands.base.commands
  • rbtools.commands.base.errors
  • rbtools.commands.base.options
  • rbtools.commands.base.output
  • rbtools.commands.alias
  • rbtools.commands.api_get
  • rbtools.commands.attach
  • rbtools.commands.clearcache
  • rbtools.commands.close
  • rbtools.commands.diff
  • rbtools.commands.info
  • rbtools.commands.install
  • rbtools.commands.land
  • rbtools.commands.list_repo_types
  • rbtools.commands.login
  • rbtools.commands.logout
  • rbtools.commands.patch
  • rbtools.commands.post
  • rbtools.commands.publish
  • rbtools.commands.review
  • rbtools.commands.setup_completion
  • rbtools.commands.setup_repo
  • rbtools.commands.stamp
  • rbtools.commands.status
  • rbtools.commands.status_update
  • rbtools.hooks
  • rbtools.hooks.common
  • rbtools.hooks.git
  • rbtools.testing
  • rbtools.testing.api
  • rbtools.testing.api.payloads
  • rbtools.testing.api.transport
  • rbtools.testing.commands
  • rbtools.testing.testcase
  • rbtools.testing.transport
  • rbtools.utils
  • rbtools.utils.aliases
  • rbtools.utils.browser
  • rbtools.utils.checks
  • rbtools.utils.commands
  • rbtools.utils.console
  • rbtools.utils.diffs
  • rbtools.utils.encoding
  • rbtools.utils.errors
  • rbtools.utils.filesystem
  • rbtools.utils.graphs
  • rbtools.utils.mimetypes
  • rbtools.utils.process
  • rbtools.utils.repository
  • rbtools.utils.review_request
  • rbtools.utils.source_tree
  • rbtools.utils.users
  • Glossary
  • General Index
  • Python Module Index
  • Release Notes
  • This documentation covers the in-development release of RBTools. You can see the stable RBTools documentation or all previous versions.

    rbtools.api.cache¶

    Caching implementation for the RBTools API.

    Module Attributes

    MINIMUM_VERSION

    The minimum version of Review Board to allow HTTP caching.

    Functions

    clear_cache([cache_path])

    Delete the HTTP cache used for the API.

    Classes

    APICache([create_db_in_memory, db_location])

    An API cache backed by a SQLite database.

    CacheEntry(url, vary_headers, max_age, etag, ...)

    An entry in the API Cache.

    CachedHTTPResponse(cache_entry)

    A response returned from the APICache.

    LiveHTTPResponse(response)

    An uncached HTTP response that can be read() more than once.

    rbtools.api.cache.MINIMUM_VERSION = '2.0.14'[source]¶

    The minimum version of Review Board to allow HTTP caching.

    Versions prior to this had broken caching. If this version or older is encountered, caching will be disabled.

    class rbtools.api.cache.CacheEntry(url: str, vary_headers: Dict[str, str], max_age: int, etag: str, local_date: datetime, last_modified: str, mime_type: str, item_mime_type: str, response_body: bytes)[source]¶

    Bases: object

    An entry in the API Cache.

    DATE_FORMAT = '%Y-%m-%dT%H:%M:%S'[source]¶
    __init__(url: str, vary_headers: Dict[str, str], max_age: int, etag: str, local_date: datetime, last_modified: str, mime_type: str, item_mime_type: str, response_body: bytes) → None[source]¶

    Create a new cache entry.

    Parameters:
    • url (str) – The URL of the entry.

    • vary_headers (dict) – The resource’s Vary header.

    • max_age (int) – The resource’s maximum cache time, in seconds.

    • etag (str) – The resource’s ETag.

    • local_date (datetime.datetime) – The local time when the cached resource was fetched.

    • last_modified (str) – The last modified date provided by the server.

    • mime_type (str) – The resource’s Content-Type.

    • item_mime_type (str) – The resource’s Item-Content-Type.

    • response_body (bytes) – The cached response body.

    matches_request(request: Request) → bool[source]¶

    Determine if the cache entry matches the given request.

    This is done by comparing the value of the headers field to the headers in the request.

    Parameters:

    request (urllib.request.Request) – The HTTP request to compare against.

    Returns:

    True if the cache entry matches the request. False otherwise.

    Return type:

    bool

    up_to_date() → bool[source]¶

    Determine if the cache entry is up to date.

    Changed in version 4.1: This now returns False if max_age is not available.

    Returns:

    True if the cache entry is still valid. False, otherwise.

    Return type:

    bool

    class rbtools.api.cache.LiveHTTPResponse(response: HTTPResponse)[source]¶

    Bases: object

    An uncached HTTP response that can be read() more than once.

    This is intended to be API-compatible with an http.client.HTTPResponse object. This allows a response to be read more than once.

    __init__(response: HTTPResponse) → None[source]¶

    Initialize the response.

    This will extract the data from the http.client response and store it.

    Parameters:

    response (http.client.HTTPResponse) – The response from the server.

    property code: int[source]¶

    The HTTP response code.

    Type:

    int

    read() → bytes[source]¶

    Return the content associated with the response.

    Returns:

    The response content.

    Return type:

    bytes

    class rbtools.api.cache.CachedHTTPResponse(cache_entry: CacheEntry)[source]¶

    Bases: object

    A response returned from the APICache.

    This is intended to be API-compatible with a urllib response object.

    __init__(cache_entry: CacheEntry) → None[source]¶

    Initialize the response.

    Parameters:

    cache_entry (CacheEntry) – The cached data.

    property code: int[source]¶

    The HTTP response code.

    Type:

    int

    read() → bytes[source]¶

    Return the content associated with the response.

    Returns:

    The cached response content.

    Return type:

    bytes

    class rbtools.api.cache.APICache(create_db_in_memory: bool = False, db_location: Optional[str] = None)[source]¶

    Bases: object

    An API cache backed by a SQLite database.

    EXPIRES_FORMAT = '%a, %d %b %Y %H:%M:%S %Z'[source]¶
    DEFAULT_CACHE_DIR = '/Users/chipx86/Library/Caches/rbtools'[source]¶
    DEFAULT_CACHE_PATH = '/Users/chipx86/Library/Caches/rbtools/apicache.db'[source]¶
    SCHEMA_VERSION = 2[source]¶
    __init__(create_db_in_memory: bool = False, db_location: Optional[str] = None) → None[source]¶

    Create a new instance of the APICache

    If the db_path is provided, it will be used as the path to the SQLite database; otherwise, the default cache (in the CACHE_DIR) will be used. The urlopen parameter determines the method that is used to open URLs.

    Changed in version 4.0: Deprecated the urlopen parameter.

    Parameters:
    • create_db_in_memory (bool, optional) – Whether to store the API cache in memory, or persist to disk.

    • db_location (str) – The filename of the cache database, if using.

    Raises:

    CacheError – The database exists but the schema could not be read.

    make_request(request: Request) → Union[LiveHTTPResponse, CachedHTTPResponse][source]¶

    Perform the specified request.

    If there is an up-to-date cached entry in our store, a CachedResponse will be returned. Otherwise, The urlopen method will be used to execute the request and a CachedResponse (if our entry is still up to date) or a Response (if it is not) will be returned.

    Parameters:

    request (urllib.request.Request) – The HTTP request to perform.

    Returns:

    The response object.

    Return type:

    LiveHTTPResponse or CachedHTTPResponse

    rbtools.api.cache.clear_cache(cache_path: str = '/Users/chipx86/Library/Caches/rbtools/apicache.db') → bool[source]¶

    Delete the HTTP cache used for the API.

    Parameters:

    cache_path (str) – The path of the cache database.

    Returns:

    True if the operation succeeded. False, otherwise.

    Return type:

    bool

    Keep up with the latest Review Board releases, security updates, and helpful information.

    About
    News
    Demo
    RBCommons Hosting
    Integrations
    Happy Users
    Support Options
    Documentation
    FAQ
    User Manual
    RBTools
    Administration Guide
    Power Pack
    Release Notes
    Downloads
    Review Board
    RBTools
    Djblets
    Power Pack
    Package Store
    PGP Signatures
    Contributing
    Bug Tracker
    Submit Patches
    Development Setup
    Wiki
    Follow Us
    Mailing Lists
    Reddit
    Twitter
    Mastodon
    Facebook
    YouTube

    Copyright © 2006-2025 Beanbag, Inc. All rights reserved.

    Terms of Service — Privacy Policy — AI Ethics Policy — Branding

    On this page

    • [Top]
    • MINIMUM_VERSION
    • CacheEntry
      • CacheEntry.DATE_FORMAT
      • CacheEntry.__init__()
      • CacheEntry.matches_request()
      • CacheEntry.up_to_date()
    • LiveHTTPResponse
      • LiveHTTPResponse.__init__()
      • LiveHTTPResponse.code
      • LiveHTTPResponse.read()
    • CachedHTTPResponse
      • CachedHTTPResponse.__init__()
      • CachedHTTPResponse.code
      • CachedHTTPResponse.read()
    • APICache
      • APICache.EXPIRES_FORMAT
      • APICache.DEFAULT_CACHE_DIR
      • APICache.DEFAULT_CACHE_PATH
      • APICache.SCHEMA_VERSION
      • APICache.__init__()
      • APICache.make_request()
    • clear_cache()