Appropriate location for my application's cache on Windows

My application caches some data on disk. Because the cache may be large, it should not be stored on a network drive. It should persist between invocations of the application. I have a mechanism for the user to choose a location, but would like the default to be sensible and "the right thing" for the platform.

What is the appropriate location for such a cache? Is there an API for determining the appropriate location? How do I call it from Python?


Have a look here: Anything that's under the users directory is good. If its for all users, then it should be: %ALLUSERSPROFILE%. If its for a specific user, make sure the permissions are right.

Check out MSDN for more info about other Windows Versions. Environment variables can vary from systems to systems.

There are a number a places you can put your application files in Windows. This page shows a list (this enum is .Net specific but most of the special folders are standard on Windows in general). Basically you'll need to decide if you need a cache per user, only for the local machine, per application or shared, etc.

I don't have much experience with python so I cannot specifically help with how to get these paths, but I'm sure someone more knowledgeable here can.

The standard location for Windows application to store their (permanent) application data is referenced by the %APPDATA% (current user) or %ALLUSERSPROFILE% (all users) environment variables. You can access them using, e.g. (only rudimentary and not very elegant error checking!):

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

Now you have your own directory for your app.

Need Your Help

Telerik RadComboBox not building

c# .net telerik

Good afternoon all (or morning for those across the pond).

Find out the type of a Profobuf message (Google Chrome Sync)

google-chrome sync protocol-buffers

I'm trying to connect to Google Chrome sync (that synchronizes your Chrome settings and your currently opened tabs).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.