def cache_disk(seconds=(86400 * 5), cache_folder='/tmp'):
 def do_cache(function):
  def inner_function(*args, **kwargs):
   'Calculate a cache key based on the decorated method signature\n            args[1] indicates the domain of the inputs, we hash on domain!\n            '
   key = sha1((str(args[1]) + str(kwargs)).encode('utf-8')).hexdigest()
   filepath = os.path.join(cache_folder, key)
   if os.path.exists(filepath):
    modified = os.path.getmtime(filepath)
    age_seconds = (time.time() - modified)
    if (age_seconds < seconds):
     return pickle.load(open(filepath, 'rb'))
   result = function(*args, **kwargs)
   pickle.dump(result, open(filepath, 'wb'))
   return result
  return inner_function
 return do_cache

def cache_disk ( seconds = ( 86400 * 5 ) , cache_folder = '/tmp' ) : def do_cache ( function ) : def inner_function ( * args , ** kwargs ) : key = sha1 ( ( str ( args [ 1 ] ) + str ( kwargs ) ) . encode ( 'utf-8' ) ) . hexdigest ( ) filepath = os . path . join ( cache_folder , key ) if os . path . exists ( filepath ) : modified = os . path . getmtime ( filepath ) age_seconds = ( time . time ( ) - modified ) if ( age_seconds < seconds ) : return pickle . load ( open ( filepath , 'rb' ) ) result = function ( * args , ** kwargs ) pickle . dump ( result , open ( filepath , 'wb' ) ) return result return inner_function return do_cache
caching extracting category locations & rss feeds for 5 days .