def cache3(func):
    cache = func()
    count = 0

    def wrapper(*args, **kwargs):
        nonlocal cache
        nonlocal count
        count += 1
        print(f'{count=}')
        if count > 3:
            count = 0
            cache = func()
        else:
            count += 1
        print(f'счетчик {count}')
        return cache

    return wrapper


@cache3
def heavy():
    print('first')
    print('Сложные вычисления')
    return 1


print('111111')
heavy()
print('222222')
heavy()
print('333333')
heavy()

def cache3(func):
    cache = func()
    count = 0

    def wrapper(*args, **kwargs):
        nonlocal cache
        nonlocal count
        count += 1
        print(f'{count=}')
        if count > 3:
            count = 0
            cache = func()
        else:
            count += 1
        print(f'счетчик {count}')
        return cache

    return wrapper


@cache3
def heavy():
    print('first')
    print('Сложные вычисления')
    return 1


print('111111')
heavy()
print('222222')
heavy()
print('333333')
heavy()
