Appropriate location for application cache in Windows

My application caches some data on disk. Because the cache can be large, it cannot be stored on a network drive. It must persist between application calls. I have a mechanism for the user to select a location, but by default it should be reasonable and "right" for the platform.

What is the right place for such a cache? Is there an API for determining a suitable location? How can I call this from Python?

+3
source share
6 answers

Have a look here: http://en.wikipedia.org/wiki/Environment_variable#User_management_variables . Everything in the user directory is good. If this is for all users, then it should be:% ALLUSERSPROFILE%. If this is for a specific user, make sure that the rights are correct.

Check out MSDN for more information on other versions of Windows. Environment variables can vary from system to system.

+2
source

, Windows. ( .Net , Windows ). , , , ..

python, , , , - .

+3

Windows () %APPDATA% ( ) %ALLUSERSPROFILE% ( ). , , , ( !):

import os
app_path = os.getenv("APPDATA") + "\\MyApplicationData"
try:
    os.mkdir(app_path)
except WindowsError:
    # already exists

.

+2

, tempfile , . Windows Temp (, , ), , . - tempfile.mkstemp(), .

. , . tempfile ( ).

+1

The module wx.StandardPathscontains methods that return various standard locations in the file system and transparently try to "correctly" Unix, Mac OS X and Windows.

+1
source

Does the application have any preferences, settings or parameters that the user can specify? If so, add a parameter in which the user can specify the location of the data, by default for the current Windows temp directory.

There is always a chance that they might not have enough disk space with a temporary directory, and he will need to use another disk / directory.

0
source

All Articles