-
Notifications
You must be signed in to change notification settings - Fork 52
Sequence cache #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Sequence cache #89
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
97dd556
Adding main classes
5c266ca
Adding main classes
09126ca
Some renames of wars and beautify
494778d
Some beautify
5d13a49
Removed LazyObject, PeclMemcached is lazy now
bcc08ab
Added explicit master and slave peers
bb67475
Some speedup of SequentialCache::get()
744f32c
Some refactor
f7d1baa
Some refactor (new lines, etc)
6bf62ae
Added typehinting to SequentialCache
e9bc4ce
CodingStyle fixes
3898128
PinbaTest fixes some error during skipping test
941b436
SequentialCache->ensureConnected => ensureTriedToConnect
d8be937
coding styles fixes
d365bcb
coding styles fixes
f8de1dc
coding style fixes
de74f00
coding style fixes
11b70f8
coding style fixes
35566ef
cosmetics
dovg 8450515
don't needed
dovg b8f7946
a bit tests tune
dovg e85e1b0
trailing slash was deleted
dovg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -7,3 +7,5 @@ test/meta/Proto/ | |
test/main/data/urls/parser.dump.new | ||
.idea | ||
test/onphp | ||
/nbproject/ | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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,132 @@ | ||
<?php | ||
/**************************************************************************** | ||
* Copyright (C) 2012 by Artem Naumenko * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU Lesser General Public License as * | ||
* published by the Free Software Foundation; either version 3 of the * | ||
* License, or (at your option) any later version. * | ||
* * | ||
****************************************************************************/ | ||
|
||
final class SequentialCache extends CachePeer | ||
{ | ||
/** | ||
* List of all peers, including master | ||
* @var array of CachePeer | ||
*/ | ||
private $list = array(); | ||
|
||
/** | ||
* List of slaves only | ||
* @var array of CachePeer | ||
*/ | ||
private $slaves = array(); | ||
|
||
/** | ||
* @var CachePeer | ||
*/ | ||
private $master = null; | ||
|
||
/** | ||
* @param CachePeer $master | ||
* @param array $slaves or CachePeer | ||
* @return SequentialCache | ||
*/ | ||
public static function create(CachePeer $master, array $slaves = array()) | ||
{ | ||
return new self($master, $slaves); | ||
} | ||
|
||
/** | ||
* @param CachePeer $master | ||
* @param array $slaves or CachePeer | ||
*/ | ||
public function __construct(CachePeer $master, array $slaves = array()) | ||
{ | ||
$this->setMaster($master); | ||
|
||
foreach ($slaves as $cache) { | ||
$this->addPeer($cache); | ||
} | ||
} | ||
|
||
/** | ||
* @param CachePeer $master | ||
* @return \SequentialCache | ||
*/ | ||
public function setMaster(CachePeer $master) | ||
{ | ||
$this->master = $master; | ||
$this->list = $this->slaves; | ||
array_unshift($this->list, $this->master); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param CachePeer $master | ||
* @return \SequentialCache | ||
*/ | ||
public function addPeer(CachePeer $peer) | ||
{ | ||
$this->list[] = $peer; | ||
$this->slaves[] = $peer; | ||
|
||
return $this; | ||
} | ||
|
||
public function get($key) | ||
{ | ||
foreach ($this->list as $val) { | ||
/* @var $val CachePeer */ | ||
$result = $val->get($key); | ||
|
||
if ( | ||
!empty($result) | ||
|| $val->isAlive() | ||
) { | ||
return $result; | ||
} | ||
} | ||
|
||
throw new RuntimeException('All peers are dead'); | ||
} | ||
|
||
public function append($key, $data) | ||
{ | ||
return $this->foreachItem(__METHOD__, func_get_args()); | ||
} | ||
|
||
public function decrement($key, $value) | ||
{ | ||
throw new UnsupportedMethodException('decrement is not supported'); | ||
} | ||
|
||
public function delete($key) | ||
{ | ||
return $this->foreachItem(__METHOD__, func_get_args()); | ||
} | ||
|
||
public function increment($key, $value) | ||
{ | ||
throw new UnsupportedMethodException('increment is not supported'); | ||
} | ||
|
||
protected function store($action, $key, $value, $expires = Cache::EXPIRES_MEDIUM) | ||
{ | ||
return $this->foreachItem(__METHOD__, func_get_args()); | ||
} | ||
|
||
private function foreachItem($method, array $args) | ||
{ | ||
$result = true; | ||
|
||
foreach ($this->list as $peer) { | ||
/* @var $peer CachePeer */ | ||
$result = call_user_func_array(array($peer, $method), $args) && $result; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не догнал. То есть в процессе работы мы можем менять параметры подключения - хост, порт, таймаут?
И после того как мы установили соединение $this->instance->pconnect() или $this->instance->connect() мы еще раз устанавливаем таймаут?
Зачем?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не, не. Смысл в том, что подключение производится только при необходимости.
Это ошибка. На самом деле там два вида таймаута - таймаут на подключение и таймаут на запрос. Можно задать оба.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну да, не заметил что $this->instance->setServerParams() а не $this->setServerParams(),