Skip to content

exception result will be used the next time when always raise in some periods #23

@pyfreyr

Description

@pyfreyr

Thanks for the awesome cache library! When the function raise exception, I found the result will cache 2 records, donot execute new.

import time
import cachebox


start = time.time()

@cachebox.cached(cachebox.TTLCache(128, ttl=10))
def sum_as_string(a, b):
    time.sleep(2)

    for _ in range(10):
        if time.time() - start < 5:
            raise ValueError(f"error at {time.time()}")
        return str(a + b)


for i in range(10):
    try:
        tic = time.time()
        result = sum_as_string(2, 2)
        print(f"{i} result: {result}")
    except Exception as e:
        print(f"{i} error: {e}")

in my computer(centos7, python3.8), the result is:

0 error: error at 1743413726.2670686
1 error: error at 1743413726.2670686
2 error: error at 1743413728.2693837
3 error: error at 1743413728.2693837
4 result: 4
5 result: 4
6 result: 4
7 result: 4
8 result: 4
9 result: 4

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions