<s> from django . contrib . sessions . backends . base import SessionBase , CreateError <EOL> from django . core . cache import cache <EOL> class SessionStore ( SessionBase ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , session_key = None ) : <EOL> self . _cache = cache <EOL> super ( SessionStore , self ) . __init__ ( session_key ) <EOL> def load ( self ) : <EOL> session_data = self . _cache . get ( self . session_key ) <EOL> if session_data is not None : <EOL> return session_data <EOL> self . create ( ) <EOL> return { } <EOL> def create ( self ) : <EOL> for i in xrange ( <NUM_LIT> ) : <EOL> self . session_key = self . _get_new_session_key ( ) <EOL> try : <EOL> self . save ( must_create = True ) <EOL> except CreateError : <EOL> continue <EOL> self . modified = True <EOL> return <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> def save ( self , must_create = False ) : <EOL> if must_create : <EOL> func = self . _cache . add <EOL> else : <EOL> func = self . _cache . set <EOL> result = func ( self . session_key , self . _get_session ( no_load = must_create ) , <EOL> self . get_expiry_age ( ) ) <EOL> if must_create and not result : <EOL> raise CreateError <EOL> def exists ( self , session_key ) : <EOL> if self . _cache . get ( session_key ) : <EOL> return True <EOL> return False <EOL> def delete ( self , session_key = None ) : <EOL> if session_key is None : <EOL> if self . _session_key is None : <EOL> return <EOL> session_key = self . _session_key <EOL> self . _cache . delete ( session_key ) </s>
