Skip to content

Commit ca27d3d

Browse files
committed
Remove Memcached from Packet class
1 parent 3402068 commit ca27d3d

File tree

2 files changed

+0
-140
lines changed

2 files changed

+0
-140
lines changed

src/libraries/Comment.php

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
class Comment implements JsonSerializable {
2121

22-
const CACHE_TTL = 300;
23-
2422
const PARENT_TYPE_DOCUMENT = 0;
2523
const PARENT_TYPE_COMMENT = 1;
2624
const PARENT_TYPE_NEWS_POST = 2;

src/libraries/Packet.php

-138
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
class Packet implements JsonSerializable {
2525

26-
const CACHE_TTL = 300;
27-
2826
const DIRECTION_CLIENT_SERVER = 1;
2927
const DIRECTION_SERVER_CLIENT = 2;
3028
const DIRECTION_PEER_TO_PEER = 3;
@@ -103,10 +101,6 @@ public static function delete($id) {
103101
$stmt->bindParam(":id", $id, PDO::PARAM_INT);
104102
$successful = $stmt->execute();
105103
$stmt->closeCursor();
106-
if ($successful) {
107-
Common::$cache->delete("bnetdocs-packet-" . (int) $id);
108-
Common::$cache->delete("bnetdocs-packets");
109-
}
110104
} catch (PDOException $e) {
111105
throw new QueryException("Cannot delete packet");
112106
} finally {
@@ -130,28 +124,6 @@ public static function &getAllPackets(
130124
$limit_clause = 'LIMIT ' . (int) $index . ',' . (int) $limit;
131125
}
132126

133-
if ( empty( $limit_clause )) {
134-
135-
$ckey = 'bnetdocs-packets-' . $where_clause
136-
. hash('md5', $order[0] . $order[1])
137-
;
138-
$cval = Common::$cache->get( $ckey );
139-
140-
if ( $cval !== false && !empty( $cval )) {
141-
142-
$ids = explode(',', $cval);
143-
$objects = [];
144-
145-
foreach ( $ids as $id ) {
146-
$objects[] = new self( $id );
147-
}
148-
149-
return $objects;
150-
151-
}
152-
153-
}
154-
155127
$order_clause =
156128
( $order ? '`' .
157129
implode( '`,`', explode( ',', $order[0] )) .
@@ -187,51 +159,23 @@ public static function &getAllPackets(
187159
throw new QueryException( 'Cannot refresh all packets' );
188160
}
189161

190-
$ids = [];
191162
$objects = [];
192-
193163
while ( $row = $stmt->fetch( PDO::FETCH_OBJ )) {
194-
$ids[] = (int) $row->id;
195164
$objects[] = new self( $row );
196-
197-
Common::$cache->set(
198-
'bnetdocs-packet-' . $row->id, serialize( $row ), self::CACHE_TTL
199-
);
200165
}
201166

202167
$stmt->closeCursor();
203-
204-
if ( empty( $limit_clause )) {
205-
Common::$cache->set( $ckey, implode( ',', $ids ), self::CACHE_TTL );
206-
}
207-
208168
return $objects;
209169

210170
} catch ( PDOException $e ) {
211-
212171
throw new QueryException( 'Cannot refresh packets', $e );
213-
214172
}
215173

216174
return null;
217175
}
218176

219177
public static function getAllPacketsBySearch($query) {
220178

221-
$cache_key = 'bnetdocs-packetsearch-' . hash( 'md5', $query );
222-
$cache_val = Common::$cache->get( $cache_key );
223-
224-
if ( $cache_val !== false && !empty( $cache_val )) {
225-
$ids = explode( ',', $cache_val );
226-
$objects = [];
227-
228-
foreach ( $ids as $id ) {
229-
$objects[] = new self( $id );
230-
}
231-
232-
return $objects;
233-
}
234-
235179
if ( !isset( Common::$database )) {
236180
Common::$database = DatabaseDriver::getDatabaseObject();
237181
}
@@ -266,28 +210,16 @@ public static function getAllPacketsBySearch($query) {
266210
throw new QueryException( 'Cannot search packets' );
267211
}
268212

269-
$ids = [];
270213
$objects = [];
271-
272214
while ( $row = $stmt->fetch( PDO::FETCH_OBJ )) {
273-
$ids[] = (int) $row->id;
274215
$objects[] = new self( $row );
275-
276-
Common::$cache->set(
277-
'bnetdocs-packet-' . $row->id, serialize( $row ), self::CACHE_TTL
278-
);
279216
}
280217

281218
$stmt->closeCursor();
282-
283-
Common::$cache->set( $cache_key, implode( ',', $ids ), self::CACHE_TTL );
284-
285219
return $objects;
286220

287221
} catch ( PDOException $e ) {
288-
289222
throw new QueryException( 'Cannot search packets', $e );
290-
291223
}
292224

293225
return null;
@@ -438,23 +370,15 @@ public static function getPacketsByUserId( $user_id ) {
438370
}
439371

440372
$packets = [];
441-
442373
while ( $row = $stmt->fetch( PDO::FETCH_OBJ )) {
443374
$packets[] = new self( $row );
444-
445-
Common::$cache->set(
446-
'bnetdocs-packet-' . $row->id, serialize( $row ), self::CACHE_TTL
447-
);
448375
}
449376

450377
$stmt->closeCursor();
451-
452378
return $packets;
453379

454380
} catch ( PDOException $e ) {
455-
456381
throw new QueryException( 'Cannot query packets by user id', $e );
457-
458382
}
459383

460384
return null;
@@ -510,13 +434,6 @@ public function getURI() {
510434

511435
public function getUsedBy() {
512436

513-
$ckey = 'bnetdocs-packetusedby-' . $this->id;
514-
$cval = Common::$cache->get($ckey);
515-
516-
if ( $cval !== false ) {
517-
return unserialize( $cval );
518-
}
519-
520437
if ( !isset( Common::$database )) {
521438
Common::$database = DatabaseDriver::getDatabaseObject();
522439
}
@@ -546,15 +463,10 @@ public function getUsedBy() {
546463
}
547464

548465
$stmt->closeCursor();
549-
550-
Common::$cache->set( $ckey, serialize( $values ), self::CACHE_TTL );
551-
552466
return $values;
553467

554468
} catch ( PDOException $e ) {
555-
556469
throw new QueryException( 'Cannot query packet used by', $e );
557-
558470
}
559471

560472
return null;
@@ -627,29 +539,6 @@ protected static function normalize( StdClass &$data ) {
627539

628540
public function refresh() {
629541

630-
$ckey = 'bnetdocs-packet-' . $this->id;
631-
$cval = Common::$cache->get( $ckey );
632-
633-
if ( $cval !== false ) {
634-
$cval = unserialize( $cval );
635-
636-
$this->created_datetime = $cval->created_datetime;
637-
$this->edited_count = $cval->edited_count;
638-
$this->edited_datetime = $cval->edited_datetime;
639-
$this->id = $cval->id;
640-
$this->options_bitmask = $cval->options_bitmask;
641-
$this->packet_application_layer_id = $cval->packet_application_layer_id;
642-
$this->packet_direction_id = $cval->packet_direction_id;
643-
$this->packet_format = $cval->packet_format;
644-
$this->packet_id = $cval->packet_id;
645-
$this->packet_name = $cval->packet_name;
646-
$this->packet_remarks = $cval->packet_remarks;
647-
$this->packet_transport_layer_id = $cval->packet_transport_layer_id;
648-
$this->user_id = $cval->user_id;
649-
650-
return true;
651-
}
652-
653542
if ( !isset( Common::$database )) {
654543
Common::$database = DatabaseDriver::getDatabaseObject();
655544
}
@@ -704,8 +593,6 @@ public function refresh() {
704593
$this->packet_transport_layer_id = $row->packet_transport_layer_id;
705594
$this->user_id = $row->user_id;
706595

707-
Common::$cache->set( $ckey, serialize( $row ), self::CACHE_TTL );
708-
709596
return true;
710597

711598
} catch ( PDOException $e ) {
@@ -807,9 +694,6 @@ public function setUsedBy( $value ) {
807694
}
808695

809696
Common::$database->commit();
810-
811-
$cache_key = 'bnetdocs-packetusedby-' . $this->id;
812-
Common::$cache->set($cache_key, serialize($value), self::CACHE_TTL);
813697
} catch (PDOException $e) {
814698
Common::$database->rollBack();
815699
throw new QueryException('Cannot update packet used by', $e);
@@ -877,32 +761,10 @@ public function update() {
877761
}
878762

879763
$stmt->closeCursor();
880-
881-
$object = new StdClass();
882-
$object->created_datetime = $this->created_datetime;
883-
$object->edited_count = $this->edited_count;
884-
$object->edited_datetime = $this->edited_datetime;
885-
$object->id = $this->id;
886-
$object->options_bitmask = $this->options_bitmask;
887-
$object->packet_application_layer_id = $this->packet_application_layer_id;
888-
$object->packet_direction_id = $this->packet_direction_id;
889-
$object->packet_format = $this->packet_format;
890-
$object->packet_id = $this->packet_id;
891-
$object->packet_name = $this->packet_name;
892-
$object->packet_remarks = $this->packet_remarks;
893-
$object->packet_transport_layer_id = $this->packet_transport_layer_id;
894-
$object->user_id = $this->user_id;
895-
896-
$cache_key = 'bnetdocs-packet-' . $this->id;
897-
Common::$cache->set( $cache_key, serialize( $object ), self::CACHE_TTL );
898-
Common::$cache->delete( 'bnetdocs-packets' );
899-
900764
return true;
901765

902766
} catch ( PDOException $e ) {
903-
904767
throw new QueryException( 'Cannot update packet', $e );
905-
906768
}
907769
return false;
908770
}

0 commit comments

Comments
 (0)