/
Config.pm
781 lines (601 loc) · 21.2 KB
/
Config.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
#!/usr/bin/perl
# A portal Config object is a class designed for wrangling Box objects.
# It loads a user's box configuration and is responsible for arranging
# and maintaining a list of the current portal box configuration in memory.
package LJ::Portal::Config;
use lib "$LJ::HOME/cgi-bin";
use LJ::Portal::Box;
# u: user object that is who this config is for
# boxes: arrayref of loaded Box objects for the user
# boxlist: arrayref of pboxid => type boxes for this user (memcached)
use fields qw(u boxes boxconfig boxlist profile);
use strict;
sub get_box_classes {
# if someone is calling this function they want to do something
# with all the modules available. To make sure nothing bad happens,
# we need to "require" all the modules specified in ljconfig. If
# the module is already loaded, splendid. If not, require will make
# sure that it's loaded so errors don't get thrown.
# require everything
LJ::Portal->load_portal_boxes(); # requires all modules in config
# return boxes, which should now all be loaded
return @LJ::PORTAL_BOXES;
}
# args: $u, $profile
# profile: time the loading of boxes (value = how many times to benchmark)
sub new {
my LJ::Portal::Config $self = shift;
$self = fields::new($self) unless ref $self;
my $u = shift;
$self->{'u'} = {};
$self->{'boxes'} = {};
$self->{'boxlist'} = {};
my $profile = shift;
$profile ||= 0;
$self->{'profile'} = $profile;
# if called with $u then load config for user
$self->load_config($u) if $u;
return $self;
}
# arguments: takes a user to load configuration for
# opts hashref (options: 'force' = force load from DB and don't
# even try memcache)
sub load_config {
my LJ::Portal::Config $self = shift;
my $u = shift;
my $opts = shift || {};
$self->{'u'} = $u if $u;
return unless $self->{'u'};
# get all portal boxes for this user:
$self->{'boxlist'} = LJ::MemCache::get($self->memcache_key) unless $opts->{'force'};
if (!$self->{'boxlist'}) {
$self->{'boxlist'} = {};
my $sth = $u->prepare("SELECT pboxid,type FROM portal_config WHERE userid=?");
$sth->execute($self->{'u'}->{'userid'});
while (my $row = $sth->fetchrow_hashref) {
my $pboxid = $row->{'pboxid'};
my $typeid = $row->{'type'};
next unless ($pboxid && $typeid);
$self->{'boxlist'}->{$pboxid} = $typeid;
}
# no boxes for user
if (!%{$self->{'boxlist'}}) {
# do we need to load the default state?
if (!$u->prop('portalinit')) {
# load default state
$self->load_default_boxes;
$u->set_prop('portalinit', localtime());
}
}
$self->update_memcache_state;
}
# load the boxes themselves
foreach my $pboxid (keys %{$self->{'boxlist'}}) {
my $typeid = $self->{'boxlist'}->{$pboxid};
next unless ($pboxid && $typeid);
my $box = $self->new_box_by_type($typeid);
next unless $box;
$box->load_config($pboxid, $self->{'u'});
$self->{'boxes'}->{$pboxid} = $box;
}
return 1;
}
# get the default column for a box class
# default is 'R' unless defined
sub get_box_default_col {
my LJ::Portal::Config $self = shift;
my $boxclass = shift;
return $LJ::PORTAL_DEFAULTBOXSTATES{$boxclass}->{'col'} || 'R';
}
# get whether or not you can have more than one of a box
sub get_box_unique {
my LJ::Portal::Config $self = shift;
my $boxclass = shift;
return $LJ::PORTAL_DEFAULTBOXSTATES{$boxclass}->{'notunique'} ? 0 : 1;
}
# add all the default boxes
sub load_default_boxes {
my LJ::Portal::Config $self = shift;
my @classes = $self->get_box_classes;
foreach my $boxclass (sort @classes) {
# check to see if the box has it's own code that needs to be run to determine
# if it should be added by default
my $fullboxclass = "LJ::Portal::Box::$boxclass";
my $toadd;
if ($fullboxclass->can('default_added')) {
$toadd = $fullboxclass->default_added($self->{'u'});
} else {
$toadd = $LJ::PORTAL_DEFAULTBOXSTATES{$boxclass} && $LJ::PORTAL_DEFAULTBOXSTATES{$boxclass}->{'added'};
}
if ($toadd) {
my $col = $self->get_box_default_col($boxclass);
my $order = $LJ::PORTAL_DEFAULTBOXSTATES{$boxclass}->{'sort'};
my $box = $self->add_box($boxclass, $col);
# does it have a default position in the column? (it should, but...)
if ($order && $box) {
$box->move(undef, $order);
}
}
}
}
# reset all of a user's settings
sub reset_all {
my LJ::Portal::Config $self = shift;
foreach my $pboxid (keys %{$self->{'boxlist'}}) {
$self->remove_box($pboxid);
}
$self->load_default_boxes;
$self->update_memcache_state;
}
# retreive all loaded boxes
sub get_boxes {
my LJ::Portal::Config $self = shift;
return $self->{'boxes'};
}
sub get_box_by_id {
my LJ::Portal::Config $self = shift;
my $id = shift;
return $self->{'boxes'}->{$id};
}
# return the key for portal config memcache
sub memcache_key {
my LJ::Portal::Config $self = shift;
if ($self->{'u'}) {
my $key = [ $self->{'u'}->{'userid'}, "prtcfg:$self->{'u'}->{'userid'}" ];
return $key;
}
return undef;
}
sub update_memcache_state {
my LJ::Portal::Config $self = shift;
LJ::MemCache::set($self->memcache_key, $self->{'boxlist'})
if $self->memcache_key && $self->{'boxlist'};
}
# return a new box object of type type
sub new_box_by_type {
my LJ::Portal::Config $self = shift;
my $type = shift;
my $typeid = int($type) ? $type : $self->type_string_to_id($type);
return undef unless (my $typename = $self->type_id_to_string($typeid));
my $class = "LJ::Portal::Box::$typename";
# if a box of this type already exists and this box type can only have one
# at a time, don't do it
if ($self->get_box_unique($typename)) {
return undef if $self->find_box_by_class($typename);
}
my $box = $class->new;
return $box;
}
# add a box
sub add_box {
my LJ::Portal::Config $self = shift;
my ($type, $column) = @_;
return unless ($type && $column && $self->{'u'});
# if this is a unique box, make sure we aren't duplicating it
if ($self->get_box_unique($type)) {
return if $self->find_box_by_class($type);
}
my $box = $self->new_box_by_type($type);
return unless $box;
my $sortorder = $self->max_sortorder($column)+1;
if ($box->create($self->{'u'}, $column, $sortorder)) {
# save box in self
$self->{'boxes'}->{$box->pboxid} = $box;
# save in memcache
my $typeid = int($type) ? $type : $self->type_string_to_id($type);
$self->{'boxlist'}->{$box->pboxid} = $typeid;
$self->update_memcache_state;
}
return $box;
}
# insert a box at the sortorder and shift all the boxes below down
sub insert_box {
my LJ::Portal::Config $self = shift;
my ($box, $col, $sortorder) = @_;
return unless ($box && $col && $sortorder);
my $insertbefore = $self->find_box($col, $sortorder);
if ($insertbefore) {
# increase the sortorder of all the boxes underneath by 1
my @colboxes = $self->get_col_boxes($col);
foreach my $cbox (@colboxes) {
if ($cbox->sortorder >= $sortorder && $cbox->pboxid != $box->pboxid) {
my $neworder = $cbox->sortorder+1;
$cbox->move($col, $neworder);
}
}
$self->update_memcache_state;
}
return $self->move_box($box, $col, $sortorder);
}
# returns a box that the current box replaced
sub move_box {
my LJ::Portal::Config $self = shift;
my ($box, $col, $sortorder) = @_;
return unless ($box && ($col || defined $sortorder));
# if no col defined use the col the box is currently in
$col ||= $box->col;
# put box at end of list if moving cols
$sortorder = $self->max_sortorder($col)+1 if !defined $sortorder;
my $samebox = $self->find_box($col, $sortorder);
if ($samebox) {
$samebox->move($col, $box->sortorder);
}
$box->move($col, $sortorder);
return $samebox;
}
sub move_box_up {
my LJ::Portal::Config $self = shift;
my $box = shift;
my $sort = $box->sortorder;
my $prevbox = $self->prev_box($box);
return undef unless $prevbox;
$self->move_box($box, $box->col, $prevbox->sortorder);
return $prevbox;
}
sub move_box_down {
my LJ::Portal::Config $self = shift;
my $box = shift;
my $sort = $box->sortorder;
my $nextbox = $self->next_box($box);
return undef unless $nextbox;
$self->move_box($box, $box->col, $nextbox->sortorder);
return $nextbox;
}
sub next_box {
my LJ::Portal::Config $self = shift;
my $box = shift;
my $sortorder = $box->sortorder;
return undef if ($sortorder >= $self->max_sortorder($box->col));
my $boxes = $self->get_boxes;
# get the boxes in this column sorted by sortorder then
# iterate through the boxes until we find the first one that
# has a greater sortorder
my @colboxes = $self->get_col_boxes($box->col); # returns sorted by sortorder
foreach my $pbox (@colboxes) {
next unless $pbox;
return $pbox if ($pbox->sortorder > $sortorder);
}
return undef;
}
sub prev_box {
my LJ::Portal::Config $self = shift;
my $box = shift;
my $sortorder = $box->sortorder;
return undef if ($sortorder <= $self->min_sortorder($box->col));
my $boxes = $self->get_boxes;
# see next_box
my @colboxes = reverse $self->get_col_boxes($box->col); # returns sorted by sortorder
foreach my $pbox (@colboxes) {
next unless $pbox;
return $pbox if ($pbox->sortorder < $sortorder);
}
return undef;
}
# returns what position in a column a box is in (not the same as sortorder)
sub col_order {
my LJ::Portal::Config $self = shift;
my $box = shift;
my $boxes = $self->get_boxes;
my @colboxes = $self->get_col_boxes($box->col); # returns sorted by sortorder
my $colorder = 1;
foreach my $cbox (@colboxes) {
last if ($cbox->pboxid == $box->pboxid);
$colorder++;
}
return $colorder;
}
sub find_box_by_col_order {
my LJ::Portal::Config $self = shift;
my ($col, $order) = @_;
my $boxes = $self->get_boxes;
my @colboxes = $self->get_col_boxes($col); # returns sorted by sortorder
foreach my $box (@colboxes) {
return $box if ($self->col_order($box) == $order);
}
return undef;
}
sub get_col_boxes {
my LJ::Portal::Config $self = shift;
my $col = shift;
my $boxes = $self->get_boxes;
# courtesy b-wizzle
return grep { $_->col eq $col }
map { $boxes->{$_} }
sort { $boxes->{$a}->sortorder <=> $boxes->{$b}->sortorder ||
$boxes->{$a}->pboxid <=> $boxes->{$b}->pboxid }
keys %$boxes;
}
# return all of the columns that have boxes
# ex. return value: ('R', 'L')
sub get_cols {
my LJ::Portal::Config $self = shift;
my $boxes = $self->get_boxes;
my %cols;
foreach my $boxkey (keys %$boxes) {
my $col = $boxes->{$boxkey}->col;
if (!$cols{$col}) {
$cols{$col} = 1;
}
}
return keys %cols;
}
# find a box based on col, sortorder
sub find_box {
my LJ::Portal::Config $self = shift;
my ($col, $sortorder) = @_;
return undef unless $col && defined $sortorder;
my $boxes = $self->get_boxes;
my @colboxes = $self->get_col_boxes($col);
foreach my $box (@colboxes) {
next unless ($box);
return $box if ($box->sortorder == $sortorder);
}
return undef;
}
# remove a box (id or object)
sub remove_box {
my LJ::Portal::Config $self = shift;
my $delbox = shift;
# if delbox is an id then get the box, otherwise it should be
# a box object
my $box = int($delbox) ? $self->{'boxes'}->{$delbox} : $delbox;
return unless $box;
my $pboxid = $box->pboxid;
my $userid = $self->{'u'}->{'userid'};
return unless $pboxid && $userid;
delete $self->{'boxes'}->{$box->{'pboxid'}};
# update memcache state:
delete $self->{'boxlist'}->{$box->{'pboxid'}};
$self->update_memcache_state;
# tell box to clean itself up and self-destruct
$box->delete;
}
sub type_string_to_id {
my LJ::Portal::Config $self = shift;
my $typestring = shift;
if (!$LJ::PORTAL_TYPEMAP{$typestring}) {
LJ::Portal->load_box_typeid($typestring);
}
my $typeid = $LJ::PORTAL_TYPEMAP{$typestring} || undef;
die "Invalid box type $typestring\n" unless $typeid;
return $typeid;
}
sub type_id_to_string {
my LJ::Portal::Config $self = shift;
my $typeid = shift;
foreach my $typestring ($self->get_box_classes) {
if (!$LJ::PORTAL_TYPEMAP{$typestring}) {
LJ::Portal->load_box_typeid($typestring);
}
if ($LJ::PORTAL_TYPEMAP{$typestring} == $typeid) {
return $typestring;
}
}
# box could not be mapped, die silently
return undef;
}
# look to see if there are any boxes of this class instantiated and return
# the first match if there is one
sub find_box_by_class {
my LJ::Portal::Config $self = shift;
my $class = shift;
my $boxes = $self->get_boxes;
foreach my $box (keys %$boxes) {
return $box if ($boxes->{$box}->box_class eq $class);
}
return undef;
}
sub min_sortorder {
my LJ::Portal::Config $self = shift;
my $col = shift;
my $boxes = $self->get_boxes;
my @colboxes = $self->get_col_boxes($col);
my $minsort = $self->max_sortorder($col);
foreach my $box (@colboxes) {
next unless $box;
$minsort = $box->sortorder if ($box->sortorder < $minsort);
}
return $minsort;
}
sub max_sortorder {
my LJ::Portal::Config $self = shift;
my $col = shift;
my $boxes = $self->get_boxes;
my @colboxes = $self->get_col_boxes($col);
my $maxsort = 0;
foreach my $box (@colboxes) {
next unless $box;
$maxsort = $box->sortorder if ($box->sortorder > $maxsort);
}
return $maxsort;
}
sub last_box {
my LJ::Portal::Config $self = shift;
my $col = shift;
my $lastsort = $self->max_sortorder($col);
return $self->find_box($col, $lastsort);
}
sub generate_box_with_container {
my LJ::Portal::Config $self = shift;
my $boxid = shift;
my $box = $self->{'boxes'}->{$boxid};
return unless $box;
my $pboxid = $box->pboxid;
my $boxinsides = $self->generate_box_insides($pboxid);
return qq{
<div class="PortalBox" id="pbox$pboxid" pboxid="$pboxid">
$boxinsides
</div>
};
}
sub generate_box_titlebar {
my LJ::Portal::Config $self = shift;
my $box = shift;
my $boxhtml = "";
my $pboxid = $box->{'pboxid'};
my $post_url = "$LJ::SITEROOT/portal/index.bml";
my $boxtitle = $box->box_name;
my $col = $box->col;
my $colorder = $self->col_order($box);
my $sort = $box->sortorder;
my $maxsort = $self->max_sortorder($col);
my $minsort = $self->min_sortorder($col);
my $editable;
if ($box->can('config_props')) {
my $props = $box->config_props;
$editable = grep { $props->{$_}->{type} ne 'hidden' } keys %$props;
}
# is there an icon for this box?
my $moduleicon = $box->box_icon;
my $closebutton = qq {
<a onclick="return deletePortalBox($pboxid);" href="$post_url?delbox=1&pboxid=$pboxid">
<img src="$LJ::IMGPREFIX/portal/PortalBoxClose.gif" title="Remove this module" />
</a>
};
my $refreshbutton = '';
if ($box->can('can_refresh') && $box->can_refresh) {
$refreshbutton = qq {
<a onclick="return reloadPortalBox($pboxid);" href="">
<img src="$LJ::IMGPREFIX/portal/PortalBoxRefresh.gif" title="Reload the contents of this module" id='refresh$pboxid' />
</a>
};
}
my $configlink;
if ($editable) {
$configlink = qq {
<a onclick="return showConfigPortalBox($pboxid);" href="$post_url?configbox=1&pboxid=$pboxid">
<img src="$LJ::IMGPREFIX/portal/PortalBoxConfig.gif" title="Edit this module"
id = 'edit$pboxid' />
</a>
};
}
# buttons to move box around
my $moveBoxButtons = '';
my $leftcol = '';
if ($col eq 'R') {
$leftcol = 'L';
}
my $rightcol = '';
if ($col eq 'L') {
$rightcol = 'R';
}
my $colpos = $self->col_order($box);
if ($leftcol) {
$moveBoxButtons .= qq{
<a onclick="return movePortalBoxToCol($pboxid, '$leftcol', $colpos);" href="$post_url?movebox=1&pboxid=$pboxid&boxcol=$leftcol&boxcolpos=$colpos">
<img src="$LJ::IMGPREFIX/portal/PortalBoxArrowLeft.gif" title="Move this module left" class="toolbutton" />
</a>
};
}
if ($rightcol) {
$moveBoxButtons .= qq{
<a onclick="return movePortalBoxToCol($pboxid, '$rightcol', $colpos);" href="$post_url?movebox=1&pboxid=$pboxid&boxcol=$rightcol&boxcolpos=$colpos">
<img src="$LJ::IMGPREFIX/portal/PortalBoxArrowRight.gif" title="Move this module right" class="toolbutton" />
</a>
};
}
if (!($sort <= $minsort)) {
$moveBoxButtons .= qq{
<a onclick="return movePortalBoxUp($pboxid);" href="$post_url?movebox=1&pboxid=$pboxid&up=1">
<img src="$LJ::IMGPREFIX/portal/PortalBoxArrowUp.gif" title="Move this module up" class="toolbutton" />
</a>
}
}
if (!($sort >= $maxsort)) {
$moveBoxButtons .= qq{
<a onclick="return movePortalBoxDown($pboxid);" href="$post_url?movebox=1&pboxid=$pboxid&down=1">
<img src="$LJ::IMGPREFIX/portal/PortalBoxArrowDown.gif" title="Move this module down" class="toolbutton" />
</a>
}
}
my $titlebarhtml = qq {
$moduleicon<span class="PortalBoxTitleText">$boxtitle</span>
<span class="PortalBoxMoveButtons" id="PortalBoxMoveButtons$pboxid">$closebutton $refreshbutton $moveBoxButtons $configlink</span>
};
return $titlebarhtml;
}
# args: boxid, force?
# force: don't use cached box contents
sub generate_box_insides {
my LJ::Portal::Config $self = shift;
my $boxid = shift;
my $force = shift;
$force ||= 0;
my $box = $self->{'boxes'}->{$boxid};
return 'Could not find box.' unless $box;
my $sort = $box->sortorder;
my $boxclass = $box->can('box_class') ? $box->box_class : '';
my $titlebar = $self->generate_box_titlebar($box);
my $content;
# don't let the box do anything if it's disabled
if ($box->box_is_disabled) {
$content = 'Sorry, this feature is disabled at this time.';
}
my $passback;
if ($LJ::PORTAL_BOX_PROFILE_START) {
$passback = $LJ::PORTAL_BOX_PROFILE_START->($box);
}
my $gencont = sub {
my $usecache = shift;
$usecache ||= 0;
if (!$content) {
$content = $self->get_box_cached_contents($box) if $usecache;
$content = $box->generate_content if !$content;
}
};
if ($LJ::IS_DEV_SERVER && $self->{'profile'}) {
eval "use Benchmark ':hireswallclock';";
return if $LJ::PORTAL_PROFILED_BOX{$boxclass};
my $runtime = Benchmark::timeit($self->{'profile'}, $gencont);
$LJ::PORTAL_DEBUG_CONTENT .= sprintf("%20s%40s", $boxclass, ": " .
Benchmark::timestr($runtime) . "\n");
$LJ::PORTAL_PROFILED_BOX{$boxclass} = 1;
} else {
$gencont->(!$force);
}
if ($LJ::PORTAL_BOX_PROFILE_END) {
$LJ::PORTAL_BOX_PROFILE_END->($passback);
}
my $ret = qq{
<div class="PortalBoxTitleBar" id="pboxtitlebar$boxid">
$titlebar
</div>
<div class="PortalBoxContent $boxclass">
$content
</div>
};
return $ret;
}
sub get_box_cached_contents {
my ($self, $box) = @_;
# is this box supposed to be memcached?
return undef unless ($box->can('cache_global'));
my $content;
my $memcachekey = $box->contents_memcache_key;
# firstly, check if there is a cache in memory
my $box_cached = LJ::MemCache::get($memcachekey);
my $time = time();
my $etag = $box->can('etag') ? $box->etag : 1;
# are the contents of this box cached?
if ($box_cached) {
my $boxcontent_cached;
my $etag_cached;
($etag_cached, $time, $boxcontent_cached) = @$box_cached;
# is it time to check to see if this content has been modified?
if (time() > $time) {
# compare etags. if they don't match, regenerate contents
if ($box->can('etag') && $etag && $box->etag == $etag_cached && $boxcontent_cached) {
$content = $boxcontent_cached;
}
# reset time
$time = time() + $box->cache_time if $box->can('cache_time');
} else {
$content = $boxcontent_cached ? $boxcontent_cached : undef;
}
}
# update memcache
$content = $box->generate_content if !$content;
LJ::MemCache::set($memcachekey, [$etag, $time, $content]);
return $content;
}
1;