Example #1
0
    def cache_data(self, host, path, response, filesize=-1):
        """
        Cache prepare data caching.

        Based on the mode, a sha256 sum is used to store data on disk.

        FIXME: incomplete download will be sent if the same file is asked.
        """
        cache_allowed = self.check_cache_allowed(host, path)
        if not cache_allowed:
            SCLogger.cache.debug('Not allowed: {0}{1}'.format(host, path))
            return self.cache_bypass(response)
        else:
            cached_file_path = self.get_cache_filepath(host, path)
            cache_file_path_tmp = self.get_cache_filepath(host, path) + '.tmp'
            cached = self.check_cached_data(
                cached_file_path, filesize=filesize)

            if cached:
                cache_hit = True
                SCLogger.cache.info('Hit: {0}{1}'.format(host, path))
                streamer = Streamer.data_cached_streamer(cached_file_path)
            else:
                cache_hit = False
                SCLogger.cache.info('Miss: {0}{1}'.format(host, path))
                streamer = Streamer.data_cacher_streamer(
                    response, cache_file_path_tmp)

            return cache_hit, cached_file_path, streamer
Example #2
0
 def cache_bypass(self, response):
     cache_hit = False
     cached_file_path = None
     streamer = Streamer.data_direct_streamer(response)
     return cache_hit, cached_file_path, streamer