You are here: Home / Documentation / How To's / How to use the LibraryCache and What is the LibraryCache Product

How to use the LibraryCache and What is the LibraryCache Product

by hietpasd published Nov 10, 2011 04:58 PM, last modified Aug 16, 2016 10:50 AM

NOTE:  This product is 0.0.2a (Alpha Release)

 

What is the LibraryCache Product?

 

The Library Cache is a simple storage based off of the Archetype Base Object.  This allows it to get all the powerful capabilities that Archetypes provide.

 

What can it do?

  • Simple Storage of any data.
  • Ability to click one button to update the data.
  • Easily add any page template for viewing the data.
  • Allows for rolling transactions via the ZMI.
  • Since it is based off Archetype it has all workflow capability.
  • Since it is based off Archetypes it can be shared by Groups or Users with all permissions.

 

What can it not do?

  • It is not used for Realtime up-to-date data, it is a cache.
  • It is not a stand-alone product, you'll need a product of your own to register your factories.

 

How does it do this?

The LibraryCache Object is very generic.  It works from your custom factory classes.  Since the factories are custom, they can do anything you want (call webservices, do logic, call sql databases, etc...)   When you create a factory, the factory will be adapted(registered) to the LibraryCache Archetype.  Now when you visit your website, you can select LibraryCache from the dropdown "Add New", you'll see the standard content edit screen with an additional dropdown.  You can select which factory this cache will use.  It will call your factory and store the results.

 

How do you use the LibraryCache Product?

 

Note: All the examples/documentation is within the uwosh.librarycache product.  There is a DummyCache fully setup to be based off of.

  • You don't have to fork this product to use it.
  • You will however need a place to put files, aka your own product.  (I might look into doing this all from the ZMI in the future).  It is only 2 files.  One is your factory, two is the already existing configure.zcml.  You can easily add these to your theme product or some other custom product if you do not want to make a whole new product.

 

1. With your own product you'll need to add a factory class. 

from uwosh.librarycache.core import CacheCore

class Dummy(CacheCore):
    """
    This is an example.  Implement build();  Add any other 
    functionality you need to do your build.
    
    Make sure build 'returns' something (your content).
    """
    
    def build(self):
        return ["1","2","5","Three Sir!","THREE!"]
  •  I highly recommend your factory format the cache results into a python List or Dictionary.  This way it is easier for the Page Template to loop through and render the stored content.  Also it is better for performance to format once on data retrieval in factory rather than every time on data display.

 

2. You'll need to register this in the configure.zcml file

<adapter factory=".example.Dummy" name="DummyCache" />

 

3.  Add this to your propertiestool.xml file in your profile/default

    <object name="cache_objects" meta_type="Plone Property Sheet">
        <property name="cache_types" type="lines">
            <element value="DummyCache" />
        </property>
    </object>
  • (I am looking into a way to remove this step all together)

 

4.  Make a simple page template (From ZMI or inside your product).  Add it to the portal_types>LibraryCache available views.

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
      lang="en"
      metal:use-macro="here/main_template/macros/master"
      i18n:domain="plone">
<body>
    
    <metal:content-core fill-slot="content-core">
        <div>
            <label>Cache Content: </label>
            <span tal:content="context/getCache" />
        </div>
    </metal:content-core>

</body>
</html>
  • Depending on how/what you store it can be accessed like such:  tal:content="context/getCache"
  • If it was pre-formatted by your factory into something like an list.  You can easily loop through:  tal:repeat="node context/getCache"
  • If the factory didn't simplify the cache and it was stored with more complexity, you might need a BrowserView controller.

 

 

Future?

  1. CRON Tab accessible next Contents, View, Sharing on the webpage.  You can setup custom cron jobs for that particular cache.
  2. Setting up some interfaces so the propertiestool.xml is no longer needed.
  3. (Unsure) Having this all done from the ZMI?  Problem facing this is you lose a lot of functionality with Module Imports.

 

 

 

 

Navigation