Use some cache in a custom fetch function

Author Message

Jerome Despatis

Thursday 01 April 2010 10:08:57 am

Hi,

 

I've done a function fetch in my extension, It may be called several times in a page, and I now the result is always the same, how can I make my fetch use a cache ?

 

I could use $GLOBALS of course and store in a specific key (hoping not to override an existing key), but I'm sure there's a better way :)

Any idea is welcome

Bertrand Dunogier

Thursday 01 April 2010 12:06:11 pm

Well, honestly, if you just need to cache temporary data for one run, you should use a global... just centralize the read/write code for these globals so that you can easily refactor it, and prefix your global names with your initials or company acronym... just like we do with eZ. There should be no conflicts this way (not more than with classes, at least :p).

If you want to implement more persistent caching, here are the options I would consider:

  • ezcCache. That's it :p
    We plan on re-implementing most caches using the Cache component from the ezComponents. It has support for hierarchical cache, and already supports standard backends (memcache, APC, files...).
    http://ezcomponents.org/docs/tutorials/Cache

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

Jerome Despatis

Thursday 01 April 2010 12:34:28 pm

Ok thanks

I already use it for plain file cache, I've seen memory cache also, let's test that...

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 02:56:02
Script start
Timing: Jan 18 2025 02:56:02
Module start 'layout'
Timing: Jan 18 2025 02:56:02
Module start 'content'
Timing: Jan 18 2025 02:56:03
Module end 'content'
Timing: Jan 18 2025 02:56:03
Script end

Main resources:

Total runtime0.7580 sec
Peak memory usage4,096.0000 KB
Database Queries58

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0069 589.1641152.6406
Module start 'layout' 0.00690.0039 741.804739.4766
Module start 'content' 0.01080.7459 781.2813536.2031
Module end 'content' 0.75670.0013 1,317.484412.1250
Script end 0.7580  1,329.6094 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.4455160.0002
Check MTime0.00130.1738160.0001
Mysql Total
Database connection0.00120.157410.0012
Mysqli_queries0.706093.1361580.0122
Looping result0.00120.1563560.0000
Template Total0.712594.020.3563
Template load0.00260.342520.0013
Template processing0.709993.656420.3550
Template load and register function0.00010.018110.0001
states
state_id_array0.00180.234810.0018
state_identifier_array0.00130.174920.0007
Override
Cache load0.00230.2986210.0001
Sytem overhead
Fetch class attribute can translate value0.00050.068520.0003
Fetch class attribute name0.00090.114840.0002
XML
Image XML parsing0.00250.329420.0012
class_abstraction
Instantiating content class attribute0.00000.001440.0000
General
dbfile0.00320.4164160.0002
String conversion0.00000.001540.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
3content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1content/datatype/view/ezxmltags/li.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/li.tplEdit templateOverride template
1content/datatype/view/ezxmltags/ul.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/ul.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 13
 Number of unique templates used: 9

Time used to render debug report: 0.0001 secs