def clear_cache(): """ Clears the cache of files. --- tags: - file responses: 200: description: Cached files. schema: properties: files: type: array items: $ref: '#/definitions/get_cached_file_get_File' 500: description: The file could not be deleted from the cache. schema: $ref: '#/definitions/allocate_instance_post_Error' """ deleted_files = [] c_dir = app.config['CACHE_CONTAINER_DIR'] for cached_file in CachedFile.get_all(): try: delete_file(cached_file) # TODO capture errors? except OSError as e: return internal_error( ('Error during the file removal from the cache. %s. ' + 'The exception raised with the following file: %s') % (e.strerror, cached_file.filename)) deleted_files.append(cached_file.serialize(c_dir)) return jsonify(files=deleted_files)
def clear_cache(): """ Clears the cache of files. --- tags: - file responses: 200: description: Cached files. schema: properties: files: type: array items: $ref: '#/definitions/get_cached_file_get_File' 500: description: The file could not be deleted from the cache. schema: $ref: '#/definitions/allocate_instance_post_Error' """ deleted_files = [] c_dir = app.config['CACHE_CONTAINER_DIR'] for cached_file in CachedFile.get_all(): try: delete_file(cached_file) # TODO capture errors? except OSError as e: return internal_error(('Error during the file removal from the cache. %s. ' + 'The exception raised with the following file: %s') % (e.strerror, cached_file.filename)) deleted_files.append(cached_file.serialize(c_dir)) return jsonify(files=deleted_files)
def list_cached_files(): """ Returns the files cached and the original URLs that they cache. --- tags: - file responses: 200: description: Cached files. schema: properties: files: type: array items: $ref: '#/definitions/get_cached_file_get_File' """ # list available files c_dir = app.config['CACHE_CONTAINER_DIR'] return jsonify(files=[cached_file.serialize(c_dir) for cached_file in CachedFile.get_all()])
def list_cached_files(): """ Returns the files cached and the original URLs that they cache. --- tags: - file responses: 200: description: Cached files. schema: properties: files: type: array items: $ref: '#/definitions/get_cached_file_get_File' """ # list available files c_dir = app.config['CACHE_CONTAINER_DIR'] return jsonify(files=[ cached_file.serialize(c_dir) for cached_file in CachedFile.get_all() ])