Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions lib/private/Memcache/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@

namespace OC\Memcache;

use \OCP\ICacheFactory;
use \OCP\ILogger;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\ILogger;
use OCP\IMemcache;

class Factory implements ICacheFactory {
const NULL_CACHE = '\\OC\\Memcache\\NullCache';
Expand Down Expand Up @@ -69,7 +71,7 @@ class Factory implements ICacheFactory {
* @param string|null $distributedCacheClass
* @param string|null $lockingCacheClass
*/
public function __construct($globalPrefix, ILogger $logger,
public function __construct(string $globalPrefix, ILogger $logger,
$localCacheClass = null, $distributedCacheClass = null, $lockingCacheClass = null)
{
$this->logger = $logger;
Expand Down Expand Up @@ -128,38 +130,39 @@ public function __construct($globalPrefix, ILogger $logger,
* create a cache instance for storing locks
*
* @param string $prefix
* @return \OCP\IMemcache
* @return IMemcache
*/
public function createLocking($prefix = '') {
public function createLocking(string $prefix = ''): IMemcache {
return new $this->lockingCacheClass($this->globalPrefix . '/' . $prefix);
}

/**
* create a distributed cache instance
*
* @param string $prefix
* @return \OC\Memcache\Cache
* @return ICache
*/
public function createDistributed($prefix = '') {
public function createDistributed(string $prefix = ''): ICache {
return new $this->distributedCacheClass($this->globalPrefix . '/' . $prefix);
}

/**
* create a local cache instance
*
* @param string $prefix
* @return \OC\Memcache\Cache
* @return ICache
*/
public function createLocal($prefix = '') {
public function createLocal(string $prefix = ''): ICache {
return new $this->localCacheClass($this->globalPrefix . '/' . $prefix);
}

/**
* @see \OC\Memcache\Factory::createDistributed()
* @param string $prefix
* @return \OC\Memcache\Cache
* @return ICache
* @deprecated 13.0.0 Use either createLocking, createDistributed or createLocal
*/
public function create($prefix = '') {
public function create(string $prefix = ''): ICache {
return $this->createDistributed($prefix);
}

Expand All @@ -168,16 +171,16 @@ public function create($prefix = '') {
*
* @return bool
*/
public function isAvailable() {
public function isAvailable(): bool {
return ($this->distributedCacheClass !== self::NULL_CACHE);
}

/**
* @see \OC\Memcache\Factory::createLocal()
* @param string $prefix
* @return Cache
* @return ICache
*/
public function createLowLatency($prefix = '') {
public function createLowLatency(string $prefix = ''): ICache {
return $this->createLocal($prefix);
}

Expand All @@ -186,7 +189,7 @@ public function createLowLatency($prefix = '') {
*
* @return bool
*/
public function isAvailableLowLatency() {
public function isAvailableLowLatency(): bool {
return ($this->localCacheClass !== self::NULL_CACHE);
}
}
19 changes: 10 additions & 9 deletions lib/public/ICacheFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
Expand Down Expand Up @@ -36,44 +37,44 @@ interface ICacheFactory{
* All entries added trough the cache instance will be namespaced by $prefix to prevent collisions between apps
*
* @param string $prefix
* @return \OCP\ICache
* @return ICache
* @since 7.0.0
* @deprecated 13.0.0 Use either createLocking, createDistributed or createLocal
*/
public function create($prefix = '');
public function create(string $prefix = ''): ICache;

/**
* Check if any memory cache backend is available
*
* @return bool
* @since 7.0.0
*/
public function isAvailable();
public function isAvailable(): bool;

/**
* create a cache instance for storing locks
*
* @param string $prefix
* @return \OCP\IMemcache
* @return IMemcache
* @since 13.0.0
*/
public function createLocking($prefix = '');
public function createLocking(string $prefix = ''): IMemcache;

/**
* create a distributed cache instance
*
* @param string $prefix
* @return \OCP\ICache
* @return ICache
* @since 13.0.0
*/
public function createDistributed($prefix = '');
public function createDistributed(string $prefix = ''): ICache;

/**
* create a local cache instance
*
* @param string $prefix
* @return \OCP\ICache
* @return ICache
* @since 13.0.0
*/
public function createLocal($prefix = '');
public function createLocal(string $prefix = ''): ICache;
}
9 changes: 5 additions & 4 deletions tests/lib/Memcache/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
*/
namespace Test\Memcache;

use OC\Memcache\NullCache;
use OCP\ILogger;

class Test_Factory_Available_Cache1 {
class Test_Factory_Available_Cache1 extends NullCache {
public function __construct($prefix = '') {
}

Expand All @@ -31,7 +32,7 @@ public static function isAvailable() {
}
}

class Test_Factory_Available_Cache2 {
class Test_Factory_Available_Cache2 extends NullCache {
public function __construct($prefix = '') {
}

Expand All @@ -40,7 +41,7 @@ public static function isAvailable() {
}
}

class Test_Factory_Unavailable_Cache1 {
class Test_Factory_Unavailable_Cache1 extends NullCache {
public function __construct($prefix = '') {
}

Expand All @@ -49,7 +50,7 @@ public static function isAvailable() {
}
}

class Test_Factory_Unavailable_Cache2 {
class Test_Factory_Unavailable_Cache2 extends NullCache {
public function __construct($prefix = '') {
}

Expand Down