Where to write cache data on Windows?

38 views
Skip to first unread message

Daniele Nicolodi

unread,
Feb 13, 2021, 4:35:02 PM2/13/21
to Beancount
Hello,

as part of the work on benagulp I wrote a small decorator to cache the
return value of functions to disk
https://github.com/beancount/beangulp/pull/33 The idea is that often
importer code needs to convert input files from PDF or other formats to
something more easily parsed. These conversions can take a sizeable
time. Currently beangulp has a facility to cache the conversions within
the same execution of the ingest mechanism, but not between runs.
Especially when developing the importer, it would be nice to speed up
the invocations. Thus this work.

This long introduction is just to ask: where should the disk cache be
located on Windows? On Unix-like platforms I think ~/.cache/benagulp/ is
the right location, but I don't know what is the equivalent of this on
Windows. I think C:\Users\<user>\AppData\Local\Beangulp could be a good
candidate, but I don't know how to get to it.

Thank you.

Cheer,
Dan

Ben Blount

unread,
Feb 13, 2021, 4:49:01 PM2/13/21
to Beancount
Windows env var %LOCALAPPDATA% should always be set.
On my windows machine that points exactly to what you are after:
>>> os.getenv("LOCALAPPDATA")
'C:\\Users\\Ben\\AppData\\Local'

Unfortunately I couldn't find any official documentation corroborating this but if Microsoft is very careful about backwards compatibility - it should be safe to rely on this key.

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/8ad06c3e-ada5-c37c-a5b5-89a19baa6073%40grinta.net.

Daniele Nicolodi

unread,
Feb 13, 2021, 5:16:26 PM2/13/21
to bean...@googlegroups.com
On 13/02/2021 22:48, Ben Blount wrote:
> Windows env var %LOCALAPPDATA% should always be set.
> On my windows machine that points exactly to what you are after:
>>>> os.getenv("LOCALAPPDATA")
> 'C:\\Users\\Ben\\AppData\\Local'
>
> Unfortunately I couldn't find any official documentation
> corroborating this but if Microsoft is very careful about backwards
> compatibility - it should be safe to rely on this key.
>

Thank you Ben. I just update the code do use the environment variable on
Windows. It would be great if someone could test the code in the PR (at
least run the unittests) on Windows.

Best,
Dan

Ben Blount

unread,
Feb 13, 2021, 5:20:20 PM2/13/21
to Beancount
I can do that, please send me the commit to verify and the invocation for the unit tests you want to check.

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.

Daniele Nicolodi

unread,
Feb 14, 2021, 6:11:29 AM2/14/21
to bean...@googlegroups.com
On 13/02/2021 23:20, Ben Blount wrote:
> I can do that, please send me the commit to verify and the invocation
> for the unit tests you want to check.

I haven't tested this exact sequence, but this should work:

git clone -b cache https://github.com/dnicolodi/beangulp.git
cd beangulp
python -m venv .
./bin/python setup.py develop
./bin/python -m unittest tests/test_cache.py
./bin/python -c 'import beangulp.cache; print(beangulp.cache.CACHEDIR)'

The last command should print the cache location.

Cheers,
Dan

Ben Blount

unread,
Feb 14, 2021, 1:30:33 PM2/14/21
to Beancount
I didn't see any relevant unit tests in https://github.com/dnicolodi/beangulp/tree/cache/tests

Here's the cache output:
python3 -c "import beangulp.cache; print(beangulp.cache.CACHEDIR)"
C:\Users\Ben\AppData\Local/Beangulp/

Consider using path.join() instead so it will handle the correct path delimiter. One of my biggest gripes with windows is that it uses \ for paths rather than /.

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.

Daniele Nicolodi

unread,
Feb 14, 2021, 2:36:08 PM2/14/21
to bean...@googlegroups.com
On 14/02/2021 19:30, Ben Blount wrote:
> I didn't see any relevant unit tests
> in https://github.com/dnicolodi/beangulp/tree/cache/tests

The test are in the file specified in the command I suggested:
tests/test_cache.py But they do not test the cache directory path, if
that is what you intended.

> Here's the cache output:
> python3 -c "import beangulp.cache; print(beangulp.cache.CACHEDIR)"
> C:\Users\Ben\AppData\Local/Beangulp/
>
> Consider using path.join() instead so it will handle the correct path
> delimiter.

Ops. Fixed.

Cheers,
Dan

Ben Blount

unread,
Feb 14, 2021, 2:47:09 PM2/14/21
to Beancount
Are you sure you commited tests/test_cache.py ? I'm not seeing it where it was supposed to be in your commands.

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.

Daniele Nicolodi

unread,
Feb 14, 2021, 3:21:06 PM2/14/21
to bean...@googlegroups.com
On 14/02/2021 20:46, Ben Blount wrote:
> Are you sure you commited tests/test_cache.py ? I'm not seeing it where
> it was supposed to be in your commands.

Sorry, I pushed the wrong branch, indeed. Thank you for persisting.

Ben Blount

unread,
Feb 15, 2021, 1:33:51 AM2/15/21
to Beancount
No problem. Tests pass on windows.

> python3 -m unittest tests/test_cache.py
.......
----------------------------------------------------------------------
Ran 7 tests in 0.031s

OK


--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages