diff --git a/lib/SimpleSAML/Store/MemcacheStore.php b/lib/SimpleSAML/Store/MemcacheStore.php
index 8a248fb6ab86b705ea5c2dbe761de1761f7c6d6b..b67a1f8acd774b21e1c53082d3057a013101aee7 100644
--- a/lib/SimpleSAML/Store/MemcacheStore.php
+++ b/lib/SimpleSAML/Store/MemcacheStore.php
@@ -26,7 +26,7 @@ class MemcacheStore implements StoreInterface
     /**
      * This function implements the constructor for this class. It loads the Memcache configuration.
      */
-    protected function __construct()
+    public function __construct()
     {
         $config = Configuration::getInstance();
         $this->prefix = $config->getString('memcache_store.prefix', 'simpleSAMLphp');
diff --git a/lib/SimpleSAML/Store/RedisStore.php b/lib/SimpleSAML/Store/RedisStore.php
index c2ddb6eb03418c8a684abee2e85b3ffbaae1fef2..20dfd28bda72ec60e9ef692472ddf4a4b557c113 100644
--- a/lib/SimpleSAML/Store/RedisStore.php
+++ b/lib/SimpleSAML/Store/RedisStore.php
@@ -14,7 +14,7 @@ use SimpleSAML\Error;
  *
  * @package simplesamlphp/simplesamlphp
  */
-class RedisStore extends StoreInterface
+class RedisStore implements StoreInterface
 {
     /** @var \Predis\Client */
     public Client $redis;
diff --git a/lib/SimpleSAML/Store/StoreFactory.php b/lib/SimpleSAML/Store/StoreFactory.php
index 847e3122e67e76130a670b753b0cef42719dfce5..d3b0f49cc2976666e01e6a92ee06368f019d3806 100644
--- a/lib/SimpleSAML/Store/StoreFactory.php
+++ b/lib/SimpleSAML/Store/StoreFactory.php
@@ -8,13 +8,14 @@ use Exception;
 use SimpleSAML\Configuration;
 use SimpleSAML\Error;
 use SimpleSAML\Module;
+use SimpleSAML\Utils;
 
 /**
  * Base class for data stores.
  *
  * @package simplesamlphp/simplesamlphp
  */
-abstract class StoreFactory
+abstract class StoreFactory implements Utils\ClearableState
 {
     /**
      * Our singleton instance.
@@ -33,7 +34,7 @@ abstract class StoreFactory
      *
      * @throws \SimpleSAML\Error\CriticalConfigurationError
      */
-    public static function getInstance(): StoreInterface
+    public static function getInstance()
     {
         if (self::$instance !== null) {
             return self::$instance;
@@ -48,13 +49,13 @@ abstract class StoreFactory
                 self::$instance = false;
                 break;
             case 'memcache':
-                self::$instance = new Store\Memcache();
+                self::$instance = new MemcacheStore();
                 break;
             case 'sql':
-                self::$instance = new Store\SQL();
+                self::$instance = new SQLStore();
                 break;
             case 'redis':
-                self::$instance = new Store\Redis();
+                self::$instance = new RedisStore();
                 break;
             default:
                 // datastore from module
@@ -75,4 +76,13 @@ abstract class StoreFactory
 
         return self::$instance;
     }
+
+
+    /**
+     * Clear any SSP specific state, such as SSP environmental variables or cached internals.
+     */
+    public static function clearInternalState(): void
+    {
+        self::$instance = null;
+    }
 }
diff --git a/modules/saml/lib/SP/LogoutStore.php b/modules/saml/lib/SP/LogoutStore.php
index ba1a3a4a8f4b70068b5e67434bb56a46a8c5fd6b..c9bea7c808dec29172f7291a8e952ebaca30fb8b 100644
--- a/modules/saml/lib/SP/LogoutStore.php
+++ b/modules/saml/lib/SP/LogoutStore.php
@@ -9,7 +9,9 @@ use SAML2\XML\saml\NameID;
 use SimpleSAML\Assert\Assert;
 use SimpleSAML\Logger;
 use SimpleSAML\Session;
-use SimpleSAML\Store;;
+use SimpleSAML\Store;
+use SimpleSAML\Store\StoreFactory;
+use SimpleSAML\Store\StoreInterface;
 use SimpleSAML\Utils;
 
 /**
@@ -23,7 +25,7 @@ class LogoutStore
     /**
      * Create logout table in SQL, if it is missing.
      *
-     * @param \SimpleSAML\Store\SQLSTore $store  The datastore.
+     * @param \SimpleSAML\Store\SQLStore $store  The datastore.
      */
     private static function createLogoutTable(Store\SQLStore $store): void
     {
@@ -354,7 +356,7 @@ class LogoutStore
             $sessionIndex = $randomUtils->generateID();
         }
 
-        $store = Store::getInstance();
+        $store = StoreFactory::getInstance();
         if ($store === false) {
             // We don't have a datastore.
             return;
@@ -390,7 +392,7 @@ class LogoutStore
      */
     public static function logoutSessions(string $authId, NameID $nameId, array $sessionIndexes)
     {
-        $store = Store::getInstance();
+        $store = StoreFactory::getInstance();
         if ($store === false) {
             // We don't have a datastore
             return false;
diff --git a/tests/Utils/StateClearer.php b/tests/Utils/StateClearer.php
index 0a9147168c1fd88453fc4b58c930c2c8bb207c0f..569c8f90eea3b514c3b8194276d73b7e8c471e0f 100644
--- a/tests/Utils/StateClearer.php
+++ b/tests/Utils/StateClearer.php
@@ -22,7 +22,7 @@ class StateClearer
     private array $clearableState = [
         'SimpleSAML\Configuration',
         'SimpleSAML\Metadata\MetaDataStorageHandler',
-        'SimpleSAML\Store',
+        'SimpleSAML\Store\StoreFactory',
         'SimpleSAML\Session'
     ];
 
diff --git a/tests/lib/SimpleSAML/Store/RedisTest.php b/tests/lib/SimpleSAML/Store/RedisStoreTest.php
similarity index 70%
rename from tests/lib/SimpleSAML/Store/RedisTest.php
rename to tests/lib/SimpleSAML/Store/RedisStoreTest.php
index 13897a991a11f8ca302ab22c2c4ef0fad4b578d9..1a149e27d5d2e94f273173bee4438ce20e5e0962 100644
--- a/tests/lib/SimpleSAML/Store/RedisTest.php
+++ b/tests/lib/SimpleSAML/Store/RedisStoreTest.php
@@ -10,6 +10,7 @@ use Predis\Client;
 use ReflectionClass;
 use SimpleSAML\Configuration;
 use SimpleSAML\Store;
+use SimpleSAML\Store\StoreFactory;
 
 /**
  * Tests for the Redis store.
@@ -20,13 +21,13 @@ use SimpleSAML\Store;
  * @covers \SimpleSAML\Store\RedisStore
  * @package simplesamlphp/simplesamlphp
  */
-class RedisTest extends TestCase
+class RedisStoreTest extends TestCase
 {
     /** @var \PHPUnit\Framework\MockObject\MockObject */
     protected MockObject $mocked_redis;
 
     /** @var \SimpleSAML\Store\RedisStore */
-    protected Store\RedisStore $redis;
+    protected Store\RedisStore $store;
 
     /** @var array */
     protected array $config;
@@ -39,7 +40,7 @@ class RedisTest extends TestCase
         $this->config = [];
 
         $this->mocked_redis = $this->getMockBuilder(Client::class)
-                                   ->setMethods(['get', 'set', 'setex', 'del', 'disconnect'])
+                                   ->setMethods(['get', 'set', 'setex', 'del', 'disconnect', '__destruct'])
                                    ->disableOriginalConstructor()
                                    ->getMock();
 
@@ -55,15 +56,7 @@ class RedisTest extends TestCase
         $this->mocked_redis->method('del')
                            ->will($this->returnCallback([$this, 'delMocked']));
 
-        $nop = /** @return void */ function () {
-            return;
-        };
-
-        $this->mocked_redis->method('disconnect')
-                           ->will($this->returnCallback($nop));
-
-        /** @var \Predis\Client $this->mocked_redis */
-        $this->redis = new Store\RedisStore($this->mocked_redis);
+        $this->store = new Store\RedisStore($this->mocked_redis);
     }
 
 
@@ -118,13 +111,8 @@ class RedisTest extends TestCase
             'store.redis.prefix' => 'phpunit_',
         ], '[ARRAY]', 'simplesaml');
 
-        /** @var \SimpleSAML\Store\RedisStore $store */
-        $store = StoreFactory::getInstance();
-
-        $this->assertInstanceOf(Store\RedisStore::class, $store);
-
+        $this->assertInstanceOf(Store\RedisStore::class, $this->store);
         $this->clearInstance($config, Configuration::class);
-//        $this->clearInstance($store, Store::class);
     }
 
 
@@ -139,13 +127,8 @@ class RedisTest extends TestCase
             'store.redis.password' => 'password',
         ], '[ARRAY]', 'simplesaml');
 
-        /** @var \SimpleSAML\Store\RedisStore $store */
-        $store = StoreFactory::getInstance();
-
-        $this->assertInstanceOf(Store\RedisStore::class, $store);
-
+        $this->assertInstanceOf(Store\RedisStore::class, $this->store);
         $this->clearInstance($config, Configuration::class);
-//        $this->clearInstance($store, Store::class);
     }
 
 
@@ -156,8 +139,8 @@ class RedisTest extends TestCase
     {
         $value = 'TEST';
 
-        $this->redis->set('test', 'key', $value);
-        $res = $this->redis->get('test', 'key');
+        $this->store->set('test', 'key', $value);
+        $res = $this->store->get('test', 'key');
         $expected = $value;
 
         $this->assertEquals($expected, $res);
@@ -171,8 +154,8 @@ class RedisTest extends TestCase
     {
         $value = 'TEST';
 
-        $this->redis->set('test', 'key', $value, $expire = 80808080);
-        $res = $this->redis->get('test', 'key');
+        $this->store->set('test', 'key', $value, $expire = 80808080);
+        $res = $this->store->get('test', 'key');
         $expected = $value;
 
         $this->assertEquals($expected, $res);
@@ -184,7 +167,7 @@ class RedisTest extends TestCase
      */
     public function testGetEmptyData(): void
     {
-        $res = $this->redis->get('test', 'key');
+        $res = $this->store->get('test', 'key');
 
         $this->assertNull($res);
     }
@@ -198,9 +181,9 @@ class RedisTest extends TestCase
         $value1 = 'TEST1';
         $value2 = 'TEST2';
 
-        $this->redis->set('test', 'key', $value1);
-        $this->redis->set('test', 'key', $value2);
-        $res = $this->redis->get('test', 'key');
+        $this->store->set('test', 'key', $value1);
+        $this->store->set('test', 'key', $value2);
+        $res = $this->store->get('test', 'key');
         $expected = $value2;
 
         $this->assertEquals($expected, $res);
@@ -212,28 +195,24 @@ class RedisTest extends TestCase
      */
     public function testDeleteData(): void
     {
-        $this->redis->set('test', 'key', 'TEST');
-        $this->redis->delete('test', 'key');
-        $res = $this->redis->get('test', 'key');
+        $this->store->set('test', 'key', 'TEST');
+        $this->store->delete('test', 'key');
+        $res = $this->store->get('test', 'key');
 
         $this->assertNull($res);
     }
 
 
     /**
-     * @param \SimpleSAML\Configuration|\SimpleSAML\Store\StoreInterface $service
+     * @param \SimpleSAML\Configuration $service
      * @param class-string $className
      */
-    protected function clearInstance($service, string $className): void
+    protected function clearInstance(Configuration $service, string $className): void
     {
         $reflectedClass = new ReflectionClass($className);
         $reflectedInstance = $reflectedClass->getProperty('instance');
         $reflectedInstance->setAccessible(true);
-        if ($service instanceof Configuration) {
-            $reflectedInstance->setValue($service, []);
-        } else {
-            $reflectedInstance->setValue($service, null);
-        }
+        $reflectedInstance->setValue($service, []);
         $reflectedInstance->setAccessible(false);
     }
 }
diff --git a/tests/lib/SimpleSAML/Store/SQLTest.php b/tests/lib/SimpleSAML/Store/SQLStoreTest.php
similarity index 51%
rename from tests/lib/SimpleSAML/Store/SQLTest.php
rename to tests/lib/SimpleSAML/Store/SQLStoreTest.php
index c6d6696bd896735f26962d98a563fff3d4dffebd..675e112aec622e9d827c9c69c6f442a9e089d077 100644
--- a/tests/lib/SimpleSAML/Store/SQLTest.php
+++ b/tests/lib/SimpleSAML/Store/SQLStoreTest.php
@@ -9,6 +9,7 @@ use ReflectionClass;
 use SimpleSAML\Configuration;
 use SimpleSAML\Store;
 use SimpleSAML\Store\StoreFactory;
+use SimpleSAML\Store\StoreInterface;
 
 /**
  * Tests for the SQL store.
@@ -17,11 +18,14 @@ use SimpleSAML\Store\StoreFactory;
  * code.
  *
  * @covers \SimpleSAML\Store\SQLStore
- *
  * @package simplesamlphp/simplesamlphp
  */
-class SQLTest extends TestCase
+class SQLStoreTest extends TestCase
 {
+    /** @var \SimpleSAML\Store\StoreInterface $store */
+    private StoreInterface $store;
+
+
     /**
      */
     protected function setUp(): void
@@ -31,6 +35,8 @@ class SQLTest extends TestCase
             'store.sql.dsn'                 => 'sqlite::memory:',
             'store.sql.prefix'              => 'phpunit_',
         ], '[ARRAY]', 'simplesaml');
+
+        $this->store = new Store\SQLStore();
     }
 
 
@@ -39,9 +45,7 @@ class SQLTest extends TestCase
      */
     public function SQLInstance(): void
     {
-        $store = StoreFactory::getInstance();
-
-        $this->assertInstanceOf(Store\SQL::class, $store);
+        $this->assertInstanceOf(Store\SQLStore::class, $this->store);
     }
 
 
@@ -50,10 +54,7 @@ class SQLTest extends TestCase
      */
     public function kvstoreTableVersion(): void
     {
-        /** @var \SimpleSAML\Store\SQLStore $store */
-        $store = StoreFactory::getInstance();
-
-        $version = $store->getTableVersion('kvstore');
+        $version = $this->store->getTableVersion('kvstore');
 
         $this->assertEquals(2, $version);
     }
@@ -64,10 +65,7 @@ class SQLTest extends TestCase
      */
     public function newTableVersion(): void
     {
-        /** @var \SimpleSAML\Store\SQLStore $store */
-        $store = StoreFactory::getInstance();
-
-        $version = $store->getTableVersion('test');
+        $version = $this->store->getTableVersion('test');
 
         $this->assertEquals(0, $version);
     }
@@ -78,11 +76,8 @@ class SQLTest extends TestCase
      */
     public function testSetTableVersion(): void
     {
-        /** @var \SimpleSAML\Store\SQLStore $store */
-        $store = StoreFactory::getInstance();
-
-        $store->setTableVersion('kvstore', 2);
-        $version = $store->getTableVersion('kvstore');
+        $this->store->setTableVersion('kvstore', 2);
+        $version = $this->store->getTableVersion('kvstore');
 
         $this->assertEquals(2, $version);
     }
@@ -93,10 +88,7 @@ class SQLTest extends TestCase
      */
     public function testGetEmptyData(): void
     {
-        /** @var \SimpleSAML\Store\SQLStore $store */
-        $store = StoreFactory::getInstance();
-
-        $value = $store->get('test', 'foo');
+        $value = $this->store->get('test', 'foo');
 
         $this->assertNull($value);
     }
@@ -107,11 +99,8 @@ class SQLTest extends TestCase
      */
     public function testInsertData(): void
     {
-        /** @var \SimpleSAML\Store\SQLStore $store */
-        $store = StoreFactory::getInstance();
-
-        $store->set('test', 'foo', 'bar');
-        $value = $store->get('test', 'foo');
+        $this->store->set('test', 'foo', 'bar');
+        $value = $this->store->get('test', 'foo');
 
         $this->assertEquals('bar', $value);
     }
@@ -122,12 +111,9 @@ class SQLTest extends TestCase
      */
     public function testOverwriteData(): void
     {
-        /** @var \SimpleSAML\Store\SQLStore $store */
-        $store = StoreFactory::getInstance();
-
-        $store->set('test', 'foo', 'bar');
-        $store->set('test', 'foo', 'baz');
-        $value = $store->get('test', 'foo');
+        $this->store->set('test', 'foo', 'bar');
+        $this->store->set('test', 'foo', 'baz');
+        $value = $this->store->get('test', 'foo');
 
         $this->assertEquals('baz', $value);
     }
@@ -138,12 +124,9 @@ class SQLTest extends TestCase
      */
     public function testDeleteData(): void
     {
-        /** @var \SimpleSAML\Store\SQLStore $store */
-        $store = StoreFactory::getInstance();
-
-        $store->set('test', 'foo', 'bar');
-        $store->delete('test', 'foo');
-        $value = $store->get('test', 'foo');
+        $this->store->set('test', 'foo', 'bar');
+        $this->store->delete('test', 'foo');
+        $value = $this->store->get('test', 'foo');
 
         $this->assertNull($value);
     }
@@ -154,13 +137,10 @@ class SQLTest extends TestCase
      */
     public function testVeryLongKey(): void
     {
-        /** @var \SimpleSAML\Store\SQLStore $store */
-        $store = StoreFactory::getInstance();
-
         $key = str_repeat('x', 100);
-        $store->set('test', $key, 'bar');
-        $store->delete('test', $key);
-        $value = $store->get('test', $key);
+        $this->store->set('test', $key, 'bar');
+        $this->store->delete('test', $key);
+        $value = $this->store->get('test', $key);
 
         $this->assertNull($value);
     }
@@ -170,30 +150,20 @@ class SQLTest extends TestCase
      */
     protected function tearDown(): void
     {
-        $config = Configuration::getInstance();
-
-        /** @var \SimpleSAML\Store\SQLStore $store */
-        $store = StoreFactory::getInstance();
-
-        $this->clearInstance($config, Configuration::class);
-//        $this->clearInstance($store, Store\SQL::class);
+        $this->clearInstance(Configuration::getInstance(), Configuration::class);
     }
 
 
     /**
-     * @param \SimpleSAML\Configuration|\SimpleSAML\Store\StoreInterface $service
+     * @param \SimpleSAML\Configuration $service
      * @param class-string $className
      */
-    protected function clearInstance($service, string $className): void
+    protected function clearInstance(Configuration $service, string $className): void
     {
         $reflectedClass = new ReflectionClass($className);
         $reflectedInstance = $reflectedClass->getProperty('instance');
         $reflectedInstance->setAccessible(true);
-        if ($service instanceof Configuration) {
-            $reflectedInstance->setValue($service, []);
-        } else {
-            $reflectedInstance->setValue($service, null);
-        }
+        $reflectedInstance->setValue($service, []);
         $reflectedInstance->setAccessible(false);
     }
 }
diff --git a/tests/lib/SimpleSAML/StoreTest.php b/tests/lib/SimpleSAML/Store/StoreFactoryTest.php
similarity index 95%
rename from tests/lib/SimpleSAML/StoreTest.php
rename to tests/lib/SimpleSAML/Store/StoreFactoryTest.php
index 967bec43a8bb3155c931003ddd1c6dded33fb3ec..75686421199ad7a7b874938a4c54754217718da3 100644
--- a/tests/lib/SimpleSAML/StoreTest.php
+++ b/tests/lib/SimpleSAML/Store/StoreFactoryTest.php
@@ -20,7 +20,7 @@ use SimpleSAML\Store\StoreFactory;
  * @covers \SimpleSAML\Store\StoreFactory
  * @package simplesamlphp/simplesamlphp
  */
-class StoreTest extends TestCase
+class StoreFactoryTest extends TestCase
 {
     /**
      * @test
@@ -124,11 +124,12 @@ class StoreTest extends TestCase
         $store = StoreFactory::getInstance();
 
         $this->clearInstance($config, Configuration::class);
+        $this->clearInstance($store, StoreFactory::class);
     }
 
 
     /**
-     * @param \SimpleSAML\Configuration|\SimpleSAML\Store\StoreInterface $service
+     * @param \SimpleSAML\Configuration|\SimpleSAML\Store\StoreFactory $service
      * @param class-string $className
      */
     protected function clearInstance($service, string $className): void
diff --git a/tests/modules/saml/lib/IdP/SQLNameIDTest.php b/tests/modules/saml/lib/IdP/SQLNameIDTest.php
index c2c849ee29ad52a75a70e22438830851e41f6fcc..098a687029ec5315ff7b73636613e372783e18b9 100644
--- a/tests/modules/saml/lib/IdP/SQLNameIDTest.php
+++ b/tests/modules/saml/lib/IdP/SQLNameIDTest.php
@@ -49,7 +49,7 @@ class SQLNameIDTest extends TestCase
         /** @var \SimpleSAML\Store\StoreInterface $store */
         $store = StoreFactory::getInstance();
         $this->clearInstance($config, Configuration::class);
-        $this->clearInstance($store, Store\SQLStore::class);
+        $this->clearInstance($store, StoreFactory::class);
     }
 
 
@@ -63,14 +63,14 @@ class SQLNameIDTest extends TestCase
             'store.type'                    => 'memcache',
         ], '[ARRAY]', 'simplesaml');
         $store = StoreFactory::getInstance();
-        $this->assertInstanceOf(Store\MemcacheStote::class, $store);
+        $this->assertInstanceOf(Store\MemcacheStore::class, $store);
         $this->expectException(Error\Exception::class);
         $this->addGetDelete();
         $config = Configuration::getInstance();
         /** @var \SimpleSAML\Store\StoreInterface $store */
-        $store = Store::getInstance();
+        $store = StoreFactory::getInstance();
         $this->clearInstance($config, Configuration::class);
-        $this->clearInstance($store, Store\MemcacheStore::class);
+        $this->clearInstance($store, StoreFactory::class);
     }
 
 
diff --git a/www/saml2/idp/ArtifactResolutionService.php b/www/saml2/idp/ArtifactResolutionService.php
index 76cc4a18504ea194b628a0a1dbcc14a4a8870acc..be3d121db3c86e00224b9bbecd5a781dc569c823 100644
--- a/www/saml2/idp/ArtifactResolutionService.php
+++ b/www/saml2/idp/ArtifactResolutionService.php
@@ -20,7 +20,7 @@ use SimpleSAML\Configuration;
 use SimpleSAML\Error;
 use SimpleSAML\Module;
 use SimpleSAML\Metadata;
-use SimpleSAML\Store;
+use SimpleSAML\Store\StoreFactory;
 
 $config = Configuration::getInstance();
 if (!$config->getBoolean('enable.saml20-idp', false) || !Module::isModuleEnabled('saml')) {
@@ -35,7 +35,7 @@ if (!$idpMetadata->getBoolean('saml20.sendartifact', false)) {
     throw new Error\Error('NOACCESS');
 }
 
-$store = Store::getInstance();
+$store = StoreFactory::getInstance();
 if ($store === false) {
     throw new Exception('Unable to send artifact without a datastore configured.');
 }