コード例 #1
0
def get_bundle_version_direct_links_cached(bundle_uuid, bundle_version):
    """
    Get the direct links in the specified BundleVersion. Since BundleVersions
    are immutable, this should be cached as aggressively as possible (ideally
    it would be infinitely but we don't want to use up all available memory).
    So this method uses lru_cache() to cache results in process-local memory.

    (Note: This can't use BundleCache because BundleCache only associates data
    with the most recent bundleversion, not a specified bundleversion)
    """
    return {
        link.name: link.direct for link in blockstore_api.get_bundle_version_links(bundle_uuid, bundle_version).values()
    }
コード例 #2
0
def get_bundle_version_direct_links_cached(bundle_uuid, bundle_version):
    """
    Get the direct links in the specified BundleVersion. Since BundleVersions
    are immutable, this should be cached as aggressively as possible.
    """
    # Use the blockstore django cache directly; this can't use BundleCache because BundleCache only associates data
    # with the most recent bundleversion, not a specified bundleversion
    cache_key = 'bundle_version_direct_links:{}:{}'.format(bundle_uuid, bundle_version)
    result = cache.get(cache_key)
    if result is None:
        result = {
            link.name: link.direct
            for link in blockstore_api.get_bundle_version_links(bundle_uuid, bundle_version).values()
        }
        cache.set(cache_key, result, timeout=None)  # Cache forever since bundle versions are immutable
    return result