'Delete and recreate the cache directory.'

@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth(member_of('admin'))
@addtoapi()
def delete_cache(self, folder='', **kwargs):

    cache_dir = os.path.join(plexpy.CONFIG.CACHE_DIR, folder)
    result = 'success'
    msg = ('Cleared    the    %scache.' % ((folder + '    ') if folder else ''))
    try:
        shutil.rmtree(cache_dir, ignore_errors=True)
    except OSError as e:
        result = 'error'
        msg = ('Failed    to    delete    %s.' % cache_dir)
        logger.exception((u'Failed    to    delete    %s:    %s.' % (cache_dir, e)))
        return {'result': result, 'message': msg}
    try:
        os.makedirs(cache_dir)
    except OSError as e:
        result = 'error'
        msg = ('Failed    to    make    %s.' % cache_dir)
        logger.exception((u'Failed    to    create    %s:    %s.' % (cache_dir, e)))
        return {'result': result, 'message': msg}
    logger.info(msg)
    return {'result': result, 'message': msg}
