-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from ackintosh/evict-outdated-memcahed-items
Fix: Memcached items keep growing
- Loading branch information
Showing
17 changed files
with
249 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
namespace Ackintosh\Ganesha; | ||
|
||
|
||
use Ackintosh\Ganesha\Storage\Adapter\SlidingTimeWindowInterface; | ||
use Ackintosh\Ganesha\Storage\Adapter\TumblingTimeWindowInterface; | ||
use Ackintosh\Ganesha\Storage\AdapterInterface; | ||
use Ackintosh\Ganesha\Strategy\Count; | ||
use Ackintosh\Ganesha\Strategy\Rate; | ||
|
||
class Context | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
const STRATEGY_COUNT = 'count'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
const STRATEGY_RATE_TUMBLING_TIME_WINDOW = 'rate_tumbling_time_window'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
const STRATEGY_RATE_SLIDING_TIME_WINDOW = 'rate_sliding_time_window'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $strategy; | ||
|
||
/** | ||
* @var Configuration | ||
*/ | ||
private $configuration; | ||
|
||
/** | ||
* @param string $strategyClass | ||
* @param AdapterInterface $adapter | ||
* @param Configuration $configuration | ||
*/ | ||
public function __construct(string $strategyClass, AdapterInterface $adapter, Configuration $configuration) | ||
{ | ||
$this->strategy = $this->determineStrategyContext($strategyClass, $adapter); | ||
$this->configuration = $configuration; | ||
} | ||
|
||
public function strategy(): string | ||
{ | ||
return $this->strategy; | ||
} | ||
|
||
public function configuration(): Configuration | ||
{ | ||
return $this->configuration; | ||
} | ||
|
||
private function determineStrategyContext(string $strategyClass, AdapterInterface $adapter): string | ||
{ | ||
switch ($strategyClass) { | ||
case Count::class: | ||
return self::STRATEGY_COUNT; | ||
break; | ||
case Rate::class: | ||
if ($adapter instanceof SlidingTimeWindowInterface) { | ||
return self::STRATEGY_RATE_SLIDING_TIME_WINDOW; | ||
} elseif ($adapter instanceof TumblingTimeWindowInterface) { | ||
return self::STRATEGY_RATE_TUMBLING_TIME_WINDOW; | ||
} else { | ||
throw new \InvalidArgumentException('Adapter should implement SlidingTimeWindowInterface or TumblingTimeWindowInterface'); | ||
} | ||
break; | ||
default: | ||
throw new \InvalidArgumentException('Unknown strategy class name: ' . $strategyClass); | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.