def get_behavior(self, *, insert: bool, update: bool) -> Callable:

    def get_call(*, fn: Callable) -> Callable:

        @wraps(self.fn)
        def call(*args, **kwargs) -> Any:
            raw_key = self.get_raw_key(*args, **kwargs)
            key = self.get_key(raw_key)
            with self._sync_lock:
                memo: _SyncMemo = self.get_memo(key, insert=insert)
                if (memo is None):
                    return fn(*args, **kwargs)
            self.expire_one_memo()
            with memo.sync_lock:
                if ((insert and (not memo.memo_return_state.called)) or (update and (memo.memo_return_state.value is not _MemoZeroValue))):
                    memo.memo_return_state.called = True
                    try:
                        memo.memo_return_state.value = fn(*args, **kwargs)
                    except Exception as e:
                        memo.memo_return_state.raised = True
                        memo.memo_return_state.value = e
                    self.bind_key_lifetime(raw_key, key)
                return self.finalize_memo(memo=memo, key=key)
        return call
    return get_call
def get_behavior(self, *, insert: bool, update: bool) -> Callable:

    def get_call(*, fn: Callable) -> Callable:

        @wraps(self.fn)
        def call(*args, **kwargs) -> Any:
            raw_key = self.get_raw_key(*args, **kwargs)
            key = self.get_key(raw_key)
            with self._sync_lock:
                memo: _SyncMemo = self.get_memo(key, insert=insert)
                if (memo is None):
                    return fn(*args, **kwargs)
            self.expire_one_memo()
            with memo.sync_lock:
                if ((insert and (not memo.memo_return_state.called)) or (update and (memo.memo_return_state.value is not _MemoZeroValue))):
                    memo.memo_return_state.called = True
                    try:
                        memo.memo_return_state.value = fn(*args, **kwargs)
                    except Exception as e:
                        memo.memo_return_state.raised = True
                        memo.memo_return_state.value = e
                    self.bind_key_lifetime(raw_key, key)
                return self.finalize_memo(memo=memo, key=key)
        return call
    return get_call