23
23
24
24
class Packet implements JsonSerializable {
25
25
26
- const CACHE_TTL = 300 ;
27
-
28
26
const DIRECTION_CLIENT_SERVER = 1 ;
29
27
const DIRECTION_SERVER_CLIENT = 2 ;
30
28
const DIRECTION_PEER_TO_PEER = 3 ;
@@ -103,10 +101,6 @@ public static function delete($id) {
103
101
$ stmt ->bindParam (":id " , $ id , PDO ::PARAM_INT );
104
102
$ successful = $ stmt ->execute ();
105
103
$ stmt ->closeCursor ();
106
- if ($ successful ) {
107
- Common::$ cache ->delete ("bnetdocs-packet- " . (int ) $ id );
108
- Common::$ cache ->delete ("bnetdocs-packets " );
109
- }
110
104
} catch (PDOException $ e ) {
111
105
throw new QueryException ("Cannot delete packet " );
112
106
} finally {
@@ -130,28 +124,6 @@ public static function &getAllPackets(
130
124
$ limit_clause = 'LIMIT ' . (int ) $ index . ', ' . (int ) $ limit ;
131
125
}
132
126
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
-
155
127
$ order_clause =
156
128
( $ order ? '` ' .
157
129
implode ( '`,` ' , explode ( ', ' , $ order [0 ] )) .
@@ -187,51 +159,23 @@ public static function &getAllPackets(
187
159
throw new QueryException ( 'Cannot refresh all packets ' );
188
160
}
189
161
190
- $ ids = [];
191
162
$ objects = [];
192
-
193
163
while ( $ row = $ stmt ->fetch ( PDO ::FETCH_OBJ )) {
194
- $ ids [] = (int ) $ row ->id ;
195
164
$ objects [] = new self ( $ row );
196
-
197
- Common::$ cache ->set (
198
- 'bnetdocs-packet- ' . $ row ->id , serialize ( $ row ), self ::CACHE_TTL
199
- );
200
165
}
201
166
202
167
$ stmt ->closeCursor ();
203
-
204
- if ( empty ( $ limit_clause )) {
205
- Common::$ cache ->set ( $ ckey , implode ( ', ' , $ ids ), self ::CACHE_TTL );
206
- }
207
-
208
168
return $ objects ;
209
169
210
170
} catch ( PDOException $ e ) {
211
-
212
171
throw new QueryException ( 'Cannot refresh packets ' , $ e );
213
-
214
172
}
215
173
216
174
return null ;
217
175
}
218
176
219
177
public static function getAllPacketsBySearch ($ query ) {
220
178
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
-
235
179
if ( !isset ( Common::$ database )) {
236
180
Common::$ database = DatabaseDriver::getDatabaseObject ();
237
181
}
@@ -266,28 +210,16 @@ public static function getAllPacketsBySearch($query) {
266
210
throw new QueryException ( 'Cannot search packets ' );
267
211
}
268
212
269
- $ ids = [];
270
213
$ objects = [];
271
-
272
214
while ( $ row = $ stmt ->fetch ( PDO ::FETCH_OBJ )) {
273
- $ ids [] = (int ) $ row ->id ;
274
215
$ objects [] = new self ( $ row );
275
-
276
- Common::$ cache ->set (
277
- 'bnetdocs-packet- ' . $ row ->id , serialize ( $ row ), self ::CACHE_TTL
278
- );
279
216
}
280
217
281
218
$ stmt ->closeCursor ();
282
-
283
- Common::$ cache ->set ( $ cache_key , implode ( ', ' , $ ids ), self ::CACHE_TTL );
284
-
285
219
return $ objects ;
286
220
287
221
} catch ( PDOException $ e ) {
288
-
289
222
throw new QueryException ( 'Cannot search packets ' , $ e );
290
-
291
223
}
292
224
293
225
return null ;
@@ -438,23 +370,15 @@ public static function getPacketsByUserId( $user_id ) {
438
370
}
439
371
440
372
$ packets = [];
441
-
442
373
while ( $ row = $ stmt ->fetch ( PDO ::FETCH_OBJ )) {
443
374
$ packets [] = new self ( $ row );
444
-
445
- Common::$ cache ->set (
446
- 'bnetdocs-packet- ' . $ row ->id , serialize ( $ row ), self ::CACHE_TTL
447
- );
448
375
}
449
376
450
377
$ stmt ->closeCursor ();
451
-
452
378
return $ packets ;
453
379
454
380
} catch ( PDOException $ e ) {
455
-
456
381
throw new QueryException ( 'Cannot query packets by user id ' , $ e );
457
-
458
382
}
459
383
460
384
return null ;
@@ -510,13 +434,6 @@ public function getURI() {
510
434
511
435
public function getUsedBy () {
512
436
513
- $ ckey = 'bnetdocs-packetusedby- ' . $ this ->id ;
514
- $ cval = Common::$ cache ->get ($ ckey );
515
-
516
- if ( $ cval !== false ) {
517
- return unserialize ( $ cval );
518
- }
519
-
520
437
if ( !isset ( Common::$ database )) {
521
438
Common::$ database = DatabaseDriver::getDatabaseObject ();
522
439
}
@@ -546,15 +463,10 @@ public function getUsedBy() {
546
463
}
547
464
548
465
$ stmt ->closeCursor ();
549
-
550
- Common::$ cache ->set ( $ ckey , serialize ( $ values ), self ::CACHE_TTL );
551
-
552
466
return $ values ;
553
467
554
468
} catch ( PDOException $ e ) {
555
-
556
469
throw new QueryException ( 'Cannot query packet used by ' , $ e );
557
-
558
470
}
559
471
560
472
return null ;
@@ -627,29 +539,6 @@ protected static function normalize( StdClass &$data ) {
627
539
628
540
public function refresh () {
629
541
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
-
653
542
if ( !isset ( Common::$ database )) {
654
543
Common::$ database = DatabaseDriver::getDatabaseObject ();
655
544
}
@@ -704,8 +593,6 @@ public function refresh() {
704
593
$ this ->packet_transport_layer_id = $ row ->packet_transport_layer_id ;
705
594
$ this ->user_id = $ row ->user_id ;
706
595
707
- Common::$ cache ->set ( $ ckey , serialize ( $ row ), self ::CACHE_TTL );
708
-
709
596
return true ;
710
597
711
598
} catch ( PDOException $ e ) {
@@ -807,9 +694,6 @@ public function setUsedBy( $value ) {
807
694
}
808
695
809
696
Common::$ database ->commit ();
810
-
811
- $ cache_key = 'bnetdocs-packetusedby- ' . $ this ->id ;
812
- Common::$ cache ->set ($ cache_key , serialize ($ value ), self ::CACHE_TTL );
813
697
} catch (PDOException $ e ) {
814
698
Common::$ database ->rollBack ();
815
699
throw new QueryException ('Cannot update packet used by ' , $ e );
@@ -877,32 +761,10 @@ public function update() {
877
761
}
878
762
879
763
$ 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
-
900
764
return true ;
901
765
902
766
} catch ( PDOException $ e ) {
903
-
904
767
throw new QueryException ( 'Cannot update packet ' , $ e );
905
-
906
768
}
907
769
return false ;
908
770
}
0 commit comments