python-diskcache icon indicating copy to clipboard operation
python-diskcache copied to clipboard

Issue with Windows/Linux Compatibility?

Open zkalson opened this issue 1 year ago • 1 comments

Hi, I have a large diskcache (~600 GB). I used rsync to sync from my local Windows machine to a Linux VM, and I am getting unusual issues on the VM.

Here's my code:

from diskcache import Cache

path = "path\to\diskcache"

FOUR_TERABYTES = 2**42
HALF_A_KILOBYTE = 2**9
DISKCACHE_SETTINGS = {
    "eviction_policy": "none",
    "size_limit": FOUR_TERABYTES,
    "disk_min_file_size": HALF_A_KILOBYTE,
}
cache = Cache(directory=path, **DISKCACHE_SETTINGS)

search_q = "search_term"
for k in cache.iterkeys():
    if search_q.lower() == k.lower():
        print(k)
        print(cache.get(k))
print(cache.get(search_q))
print(cache[search_q])

The above code works as expected on my local Windows machine. On my Linux machine, the output is:

search_term None None Traceback (most recent call last): File "/home/username/repo/diskcache_test.py", line 27, in print(cache[search_q]) ~~~~~^^^^^^^^^^ File "/home/username/repo/.venv/lib/python3.11/site-packages/diskcache/core.py", line 1234, in getitem raise KeyError(key) KeyError: 'search_term'

In other words, it finds the key (but not the associated non-None value). Then, when directly accessing the key, I get a KeyError.

Any idea what might be going on here?

zkalson avatar Nov 14 '24 02:11 zkalson

I was able to resolve using the command offered in #304

zkalson avatar Nov 14 '24 23:11 zkalson

Thanks for reporting back. This issue can be closed :)

jonnor avatar Jul 17 '25 11:07 jonnor