diff --git a/plugins/cas_auth_unl/composer.json b/plugins/cas_auth_unl/composer.json
index 236d9a90d0d89b40287551f71d4bf59a4cb7a09c..7c83a301fb7b1803d94fd30110350823df2532eb 100644
--- a/plugins/cas_auth_unl/composer.json
+++ b/plugins/cas_auth_unl/composer.json
@@ -1,5 +1,6 @@
 {
   "require": {
-    "jasig/phpcas": "~1.3"
+    "jasig/phpcas": "~1.3",
+    "tedivm/stash": "~0.13"
   }
-}
\ No newline at end of file
+}
diff --git a/plugins/cas_auth_unl/composer.lock b/plugins/cas_auth_unl/composer.lock
index 4d158275cda2c309b0c8967e29f3f48eccd2cbf0..1cba62280418b3b4476f41068d2c5040d582dc0e 100644
--- a/plugins/cas_auth_unl/composer.lock
+++ b/plugins/cas_auth_unl/composer.lock
@@ -4,8 +4,8 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "hash": "c72657decb399fc38e48dad429f7985b",
-    "content-hash": "3c9c7d5916350b6e3fdebf1a226410b8",
+    "hash": "b4245ecc009711f2dc14b812d7df3801",
+    "content-hash": "6100f9d8f438ea02c6cc1e2fdb4f9075",
     "packages": [
         {
             "name": "jasig/phpcas",
@@ -60,6 +60,60 @@
                 "jasig"
             ],
             "time": "2015-11-16 20:44:36"
+        },
+        {
+            "name": "tedivm/stash",
+            "version": "v0.13.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/tedious/Stash.git",
+                "reference": "3489b13bad93c81a898fcb1054ae954575e1a7b6"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/tedious/Stash/zipball/3489b13bad93c81a898fcb1054ae954575e1a7b6",
+                "reference": "3489b13bad93c81a898fcb1054ae954575e1a7b6",
+                "shasum": ""
+            },
+            "require": {
+                "php": "^5.4|^7.0"
+            },
+            "require-dev": {
+                "fabpot/php-cs-fixer": "^1.9",
+                "phpunit/phpunit": "4.7.*",
+                "satooshi/php-coveralls": "1.0.*"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Stash\\": "src/Stash/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "BSD-3-Clause"
+            ],
+            "authors": [
+                {
+                    "name": "Robert Hafner",
+                    "email": "tedivm@tedivm.com"
+                },
+                {
+                    "name": "Josh Hall-Bachner",
+                    "email": "charlequin@gmail.com"
+                }
+            ],
+            "description": "The place to keep your cache.",
+            "homepage": "http://github.com/tedious/Stash",
+            "keywords": [
+                "apc",
+                "cache",
+                "caching",
+                "memcached",
+                "redis",
+                "sessions"
+            ],
+            "time": "2015-12-29 00:07:05"
         }
     ],
     "packages-dev": [],
diff --git a/plugins/cas_auth_unl/start.php b/plugins/cas_auth_unl/start.php
index 3cdf4510df250eabb71219738866f553ace30932..85214eff85fd04d6a7b4dfcfbe8d69cd3e15ee22 100644
--- a/plugins/cas_auth_unl/start.php
+++ b/plugins/cas_auth_unl/start.php
@@ -115,48 +115,46 @@ class elggSimpleCas {
 
                 $session = elgg_get_session();
 
-                $file = $this->getSessionMapFileName();
-                if (!file_exists($file)) {
-                    //Create it if it doesn't exist
-                    file_put_contents($file, json_encode(array()));
-                }
-                
-                $map = json_decode(file_get_contents($file), true);
-                $map[$logoutTicket] = array(
+                $pool = $auth->getSessionMapPool();
+                $item = $pool->getItem($logoutTicket);
+                $item->set(array(
                     'session_id' => $session->getId(),
                     'date_created' => time()
-                );
-                
-                file_put_contents($file, json_encode($map));
+                ));
             });
             
             \phpCAS::setSingleSignoutCallback(function ($logoutTicket) {
-                $file = $this->getSessionMapFileName();
-                
-                if (!file_exists($file)) {
-                    return false;
+                $auth = new elggSimpleCas();
+                $pool = $auth->getSessionMapPool();
+                $item = $pool->getItem($logoutTicket);
+
+                if ($item->isMiss()) {
+                    return null;
                 }
                 
-                $map = json_decode(file_get_contents($file), true);
-                
-                if (!isset($map[$logoutTicket])) {
-                    return false;
-                }
+                $data = $item->get();
 
                 $handler = new Elgg\Http\DatabaseSessionHandler(_elgg_services()->db);
-                $handler->destroy($map[$logoutTicket]['session_id']);
+                $handler->destroy($data['session_id']);
                 
-                unset($map[$logoutTicket]);
-                file_put_contents($file, json_encode($map));
-                //TODO: What about file locking? Use STASH instead?
+                //Remove the cached item
+                $item->clear();
             });
             
         }
     }
     
-    protected function getSessionMapFileName()
+    public function getSessionMapPool()
     {
-        return sys_get_temp_dir() .'/elgg_session_map_' . md5(__DIR__) . '.json';
+        $driver = new Stash\Driver\FileSystem();
+
+        // Setting a custom path is done by passing an options array to the constructor.
+        $options = array('path' => sys_get_temp_dir() .'/elgg_session_map_' . md5(__DIR__));
+        $driver->setOptions($options);
+
+        $pool = new Stash\Pool($driver);
+        
+        return $pool;
     }
     
     public function singleLogOut()