<s> import time <EOL> _channel_repository_cache = { } <EOL> def clear_cache ( ) : <EOL> global _channel_repository_cache <EOL> _channel_repository_cache = { } <EOL> def get_cache ( key , default = None ) : <EOL> """<STR_LIT>""" <EOL> struct = _channel_repository_cache . get ( key , { } ) <EOL> expires = struct . get ( '<STR_LIT>' ) <EOL> if expires and expires > time . time ( ) : <EOL> return struct . get ( '<STR_LIT:data>' ) <EOL> return default <EOL> def merge_cache_over_settings ( destination , setting , key_prefix ) : <EOL> """<STR_LIT>""" <EOL> existing = destination . settings . get ( setting , { } ) <EOL> value = get_cache ( key_prefix + '<STR_LIT:.>' + setting , { } ) <EOL> if value : <EOL> existing . update ( value ) <EOL> destination . settings [ setting ] = existing <EOL> def merge_cache_under_settings ( destination , setting , key_prefix , list_ = False ) : <EOL> """<STR_LIT>""" <EOL> default = { } if not list_ else [ ] <EOL> existing = destination . settings . get ( setting ) <EOL> value = get_cache ( key_prefix + '<STR_LIT:.>' + setting , default ) <EOL> if value : <EOL> if existing : <EOL> if list_ : <EOL> base = dict ( zip ( value , [ None ] * len ( value ) ) ) <EOL> for val in existing : <EOL> if val in base : <EOL> continue <EOL> value . append ( val ) <EOL> else : <EOL> value . update ( existing ) <EOL> destination . settings [ setting ] = value <EOL> def set_cache ( key , data , ttl = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> _channel_repository_cache [ key ] = { <EOL> '<STR_LIT:data>' : data , <EOL> '<STR_LIT>' : time . time ( ) + ttl <EOL> } <EOL> def set_cache_over_settings ( destination , setting , key_prefix , value , ttl ) : <EOL> """<STR_LIT>""" <EOL> existing = destination . settings . get ( setting , { } ) <EOL> existing . update ( value ) <EOL> set_cache ( key_prefix + '<STR_LIT:.>' + setting , value , ttl ) <EOL> destination . settings [ setting ] = value <EOL> def set_cache_under_settings ( destination , setting , key_prefix , value , ttl , list_ = False ) : <EOL> """<STR_LIT>""" <EOL> default = { } if not list_ else [ ] <EOL> existing = destination . settings . get ( setting , default ) <EOL> if value : <EOL> if list_ : <EOL> value . extend ( existing ) <EOL> else : <EOL> value . update ( existing ) <EOL> set_cache ( key_prefix + '<STR_LIT:.>' + setting , value , ttl ) <EOL> destination . settings [ setting ] = value </s>
