예제 #1
0
def get_bundle_version_files_cached(bundle_uuid, bundle_version):
    """
    Get the files 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 blockstore_api.get_bundle_version_files(bundle_uuid, bundle_version)
예제 #2
0
def get_bundle_version_files_cached(bundle_uuid, bundle_version):
    """
    Get the files 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
    # This key is '_v2' to avoid reading invalid values cached by a past version of this code with no timeout.
    cache_key = 'bundle_version_files_v2:{}:{}'.format(bundle_uuid, bundle_version)
    result = cache.get(cache_key)
    if result is None:
        result = blockstore_api.get_bundle_version_files(bundle_uuid, bundle_version)
        # Cache this result. We should be able to cache this forever, since bundle versions are immutable, but currently
        # this result may contain signed S3 URLs which become invalid after 3600 seconds. If Blockstore is improved to
        # return URLs that redirect to the signed S3 URLs, then this can be changed to cache forever.
        cache.set(cache_key, result, timeout=1800)
    return result