<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def clear_cache(self, urlpath):
 """ Clears cache and metadata for a given urlpath. Parameters urlpath: str, location of data May be a local path, or remote path if including a protocol specifier such as ``'s3://'``. May include glob wildcards. """

        cache_entries = self._metadata.pop(urlpath, [])  # ignore if missing
        for cache_entry in cache_entries:
            try:
                os.remove(cache_entry['cache_path'])
            except (OSError, IOError):
                pass
        try:
            fn = os.path.dirname(cache_entry['cache_path'])
            os.rmdir(fn)
        except (OSError, IOError):
            logger.debug("Failed to remove cache directory: %s" % fn)