diff --git a/pyopencl/cache.py b/pyopencl/cache.py
index 0db15d6e257045aedd069047f39d2f5fd004a5ef..6d054648ae5cc84530c61ffc85744a36780444a2 100644
--- a/pyopencl/cache.py
+++ b/pyopencl/cache.py
@@ -337,16 +337,15 @@ def _create_built_program_from_source_cached(ctx, src, options, devices, cache_d
             option_idx += 1
 
     if cache_dir is None:
-        from tempfile import gettempdir
-        import getpass
-        cache_dir = join(gettempdir(),
-                "pyopencl-compiler-cache-v2-uid%s-py%s" % (
-                    getpass.getuser(), ".".join(str(i) for i in sys.version_info)))
+        import appdirs
+        cache_dir = join(appdirs.user_cache_dir("pyopencl", "pyopencl"),
+                "pyopencl-compiler-cache-v2-py%s" % (
+                    ".".join(str(i) for i in sys.version_info),))
 
     # {{{ ensure cache directory exists
 
     try:
-        os.mkdir(cache_dir)
+        os.makedirs(cache_dir)
     except OSError, e:
         from errno import EEXIST
         if e.errno != EEXIST:
diff --git a/setup.py b/setup.py
index 4ef1f888012e6071dae3aa25d34674ba8a3667fd..6dc78e516442fef9429e462a03ef7c7186f88eb6 100644
--- a/setup.py
+++ b/setup.py
@@ -208,6 +208,7 @@ def main():
                 "pytools>=2014.2",
                 "pytest>=2",
                 "decorator>=3.2.0",
+                "appdirs>=1.4.0",
                 # "Mako>=0.3.6",
                 ],