          self.assertEqual(relpath, "cached/url.615e21601e4b.css")
          with storage.staticfiles_storage.open(relpath) as relfile:
              self.assertIn(b"https://", relfile.read())
  
      def test_cache_invalidation(self):
          name = "cached/styles.css"
          hashed_name = "cached/styles.93b1147e8552.css"
          # check if the cache is filled correctly as expected
          cache_key = storage.staticfiles_storage.cache_key(name)
          cached_name = storage.staticfiles_storage.cache.get(cache_key)
          self.assertEqual(self.cached_file_path(name), cached_name)
          # clearing the cache to make sure we re-set it correctly in the url method
          storage.staticfiles_storage.cache.clear()
          cached_name = storage.staticfiles_storage.cache.get(cache_key)
          self.assertEqual(cached_name, None)
          self.assertEqual(self.cached_file_path(name), hashed_name)
          cached_name = storage.staticfiles_storage.cache.get(cache_key)
          self.assertEqual(cached_name, hashed_name)
  
      def test_post_processing(self):
          """Test that post_processing behaves correctly.
  
          Files that are alterable should always be post-processed; files that
          aren't should be skipped.
 
</s> remove                 cache_key = self.cache_key(name)
                hashed_name = self.cache.get(cache_key)
                if hashed_name is None:
                    hashed_name = self.hashed_name(clean_name).replace('\\', '/')
                    # set the cache if there was a miss
                    # (e.g. if cache server goes down)
                    self.cache.set(cache_key, hashed_name)
 </s> add                 hashed_name = self.stored_name(clean_name) </s> remove         relpath = self.cached_file_path("cached/url.css")
 </s> add         relpath = self.hashed_file_path("cached/url.css") </s> remove         # Finally set the cache
        self.cache.set_many(hashed_paths)
 </s> add         # Finally store the processed paths
        self.hashed_files.update(hashed_files)

    def clean_name(self, name):
        return name.replace('\\', '/')

    def hash_key(self, name):
        return name

    def stored_name(self, name):
        hash_key = self.hash_key(name)
        cache_name = self.hashed_files.get(hash_key)
        if cache_name is None:
            cache_name = self.clean_name(self.hashed_name(name))
            # store the hashed name if there was a miss, e.g.
            # when the files are still processed
            self.hashed_files[hash_key] = cache_name
        return cache_name


class ManifestFilesMixin(HashedFilesMixin):
    manifest_version = '1.0'  # the manifest format standard
    manifest_name = 'staticfiles.json'

    def __init__(self, *args, **kwargs):
        super(ManifestFilesMixin, self).__init__(*args, **kwargs)
        self.hashed_files = self.load_manifest()

    def read_manifest(self):
        try:
            with self.open(self.manifest_name) as manifest:
                return manifest.read()
        except IOError:
            return None

    def load_manifest(self):
        content = self.read_manifest()
        if content is None:
            return OrderedDict()
        try:
            stored = json.loads(content, object_pairs_hook=OrderedDict)
        except ValueError:
            pass
        else:
            version = stored.get('version', None)
            if version == '1.0':
                return stored.get('paths', OrderedDict())
        raise ValueError("Couldn't load manifest '%s' (version %s)" %
                         (self.manifest_name, self.manifest_version))

    def post_process(self, *args, **kwargs):
        all_post_processed = super(ManifestFilesMixin,
                                   self).post_process(*args, **kwargs)
        for post_processed in all_post_processed:
            yield post_processed
        payload = {'paths': self.hashed_files, 'version': self.manifest_version}
        if self.exists(self.manifest_name):
            self.delete(self.manifest_name)
        self._save(self.manifest_name, ContentFile(json.dumps(payload)))


class _MappingCache(object):
    """
    A small dict-like wrapper for a given cache backend instance.
    """
    def __init__(self, cache):
        self.cache = cache

    def __setitem__(self, key, value):
        self.cache.set(key, value)

    def __getitem__(self, key):
        value = self.cache.get(key, None)
        if value is None:
            raise KeyError("Couldn't find a file name '%s'" % key)
        return value

    def clear(self):
        self.cache.clear()

    def update(self, data):
        self.cache.set_many(data)

    def get(self, key, default=None):
        try:
            return self[key]
        except KeyError:
            return default


class CachedFilesMixin(HashedFilesMixin):
    def __init__(self, *args, **kwargs):
        super(CachedFilesMixin, self).__init__(*args, **kwargs)
        try:
            self.hashed_files = _MappingCache(caches['staticfiles'])
        except InvalidCacheBackendError:
            # Use the default backend
            self.hashed_files = _MappingCache(default_cache)

    def hash_key(self, name):
        key = hashlib.md5(force_bytes(self.clean_name(name))).hexdigest()
        return 'staticfiles:%s' % key </s> remove         final_url = super(CachedFilesMixin, self).url(hashed_name)
 </s> add         final_url = super(HashedFilesMixin, self).url(hashed_name) </s> remove     A subclass of the :class:`~django.contrib.staticfiles.storage.StaticFilesStorage`
    storage backend which caches the files it saves by appending the MD5 hash
    of the file's content to the filename. For example, the file
    ``css/styles.css`` would also be saved as ``css/styles.55e7cbb9ba48.css``.

    The purpose of this storage is to keep serving the old files in case some
    pages still refer to those files, e.g. because they are cached by you or
    a 3rd party proxy server. Additionally, it's very helpful if you want to
    apply `far future Expires headers`_ to the deployed files to speed up the
    load time for subsequent page visits.

    The storage backend automatically replaces the paths found in the saved
    files matching other saved files with the path of the cached copy (using
    the :meth:`~django.contrib.staticfiles.storage.StaticFilesStorage.post_process`
    method). The regular expressions used to find those paths
    (``django.contrib.staticfiles.storage.CachedStaticFilesStorage.cached_patterns``)
    by default cover the `@import`_ rule and `url()`_ statement of `Cascading
    Style Sheets`_. For example, the ``'css/styles.css'`` file with the
    content

    .. code-block:: css+django

        @import url("../admin/css/base.css");

    would be replaced by calling the
    :meth:`~django.core.files.storage.Storage.url`
    method of the ``CachedStaticFilesStorage`` storage backend, ultimately
    saving a ``'css/styles.55e7cbb9ba48.css'`` file with the following
    content:

    .. code-block:: css+django

        @import url("../admin/css/base.27e20196a850.css");

    To enable the ``CachedStaticFilesStorage`` you have to make sure the
    following requirements are met:

    * the :setting:`STATICFILES_STORAGE` setting is set to
      ``'django.contrib.staticfiles.storage.CachedStaticFilesStorage'``
    * the :setting:`DEBUG` setting is set to ``False``
    * you use the ``staticfiles`` :ttag:`static<staticfiles-static>` template
      tag to refer to your static files in your templates
    * you've collected all your static files by using the
      :djadmin:`collectstatic` management command

    Since creating the MD5 hash can be a performance burden to your website
    during runtime, ``staticfiles`` will automatically try to cache the
    hashed name for each file path using Django's :doc:`caching
    framework</topics/cache>`. If you want to override certain options of the
    cache backend the storage uses, simply specify a custom entry in the
    :setting:`CACHES` setting named ``'staticfiles'``. It falls back to using
    the ``'default'`` cache backend.

    .. method:: file_hash(name, content=None)

    The method that is used when creating the hashed name of a file.
    Needs to return a hash for the given file name and content.
    By default it calculates a MD5 hash from the content's chunks as
    mentioned above.
 </s> add     @import url("../admin/css/base.27e20196a850.css");

To enable the ``ManifestStaticFilesStorage`` you have to make sure the
following requirements are met:

* the :setting:`STATICFILES_STORAGE` setting is set to
  ``'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'``
* the :setting:`DEBUG` setting is set to ``False``
* you use the ``staticfiles`` :ttag:`static<staticfiles-static>` template
  tag to refer to your static files in your templates
* you've collected all your static files by using the
  :djadmin:`collectstatic` management command

Since creating the MD5 hash can be a performance burden to your website
during runtime, ``staticfiles`` will automatically store the mapping with
hashed names for all processed files in a file called ``staticfiles.json``.
This happens once when you run the :djadmin:`collectstatic` management
command.

.. method:: file_hash(name, content=None)

The method that is used when creating the hashed name of a file.
Needs to return a hash for the given file name and content.
By default it calculates a MD5 hash from the content's chunks as
mentioned above. Feel free to override this method to use your own
hashing algorithm.
          self.assertEqual(relpath, "cached/url.615e21601e4b.css")
          with storage.staticfiles_storage.open(relpath) as relfile:
              self.assertIn(b"https://", relfile.read())
  















      def test_post_processing(self):
          """Test that post_processing behaves correctly.
  
          Files that are alterable should always be post-processed; files that
          aren't should be skipped.
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Added ManifestStaticFilesStorage to staticfiles contrib app.

It uses a static manifest file that is created when running
collectstatic in the JSON format. 
tests/staticfiles_tests/tests.py