def _enable_lock(func):
@functools.wraps(func)<EOL>def wrapper(*args, **kwargs):<EOL><INDENT>self = args[<NUM_LIT:0>]<EOL>if self.is_concurrent:<EOL><INDENT>only_read = kwargs.get('<STR_LIT>')<EOL>if only_read is None or only_read:<EOL><INDENT>with self._rwlock:<EOL><INDENT>return func(*args, **kwargs)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self._rwlock.acquire_writer()<EOL>try:<EOL><INDENT>return func(*args, **kwargs)<EOL><DEDENT>finally:<EOL><INDENT>self._rwlock.release()<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>return func(*args, **kwargs)<EOL><DEDENT><DEDENT>return wrapper<EOL>
The decorator for ensuring thread-safe when current cache instance is concurrent status.