[Zope3-checkins] CVS: Zope3/src/zope/app/cache/browser - __init__.py:1.1 cacheable.py:1.1 cacheableedit.pt:1.1 configure.zcml:1.1 ram.py:1.1 ramedit.pt:1.1 ramstats.pt:1.1

Philipp von Weitershausen philikon at philikon.de
Mon Mar 1 05:57:37 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/cache/browser
In directory cvs.zope.org:/tmp/cvs-serv22236/cache/browser

Added Files:
	__init__.py cacheable.py cacheableedit.pt configure.zcml 
	ram.py ramedit.pt ramstats.pt 
Log Message:
Combined all cache-related code in the zope.app.cache package, except
for the cache service which is going to be converted to a utility anyway.


=== Added File Zope3/src/zope/app/cache/browser/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/app/cache/browser/cacheable.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Management view for binding caches to content objects.

$Id: cacheable.py,v 1.1 2004/03/01 10:57:35 philikon Exp $
"""
from zope.app import zapi
from zope.app.cache.caching import getCacheForObj, getLocationForCache
from zope.app.form.utility import setUpEditWidgets
from zope.app.i18n import ZopeMessageIDFactory as _
from zope.app.interfaces.annotation import IAnnotatable
from zope.app.cache.interfaces import ICacheable
from zope.app.interfaces.form import WidgetInputError
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.app.publisher.browser import BrowserView

class CacheableView(BrowserView):

    __used_for__ = IAnnotatable

    form = ViewPageTemplateFile("cacheableedit.pt")

    def __init__(self, *args):
        super(CacheableView, self).__init__(*args)
        self.cacheable = zapi.getAdapter(self.context, ICacheable)
        setUpEditWidgets(self, ICacheable, self.cacheable)

    def current_cache_id(self):
        "Returns the current cache ID."
        return self.cacheable.getCacheId()

    def current_cache_url(self):
        "Returns the current cache provider's URL."
        # XXX: it would be *really* useful to the user to be able to jump to
        # the cache component and see the stats etc. directly from the
        # cacheable view.  All this needs is to find out the URL somehow.
        return None

    def invalidate(self):
        "Invalidate the current cached value."

        cache = getCacheForObj(self.context)
        location = getLocationForCache(self.context)
        if cache and location:
            cache.invalidate(location)
            return self.form(message=_("cache-invalidated", u"Invalidated."))
        else:
            return self.form(message=_("no-cache-associated",
                                       u"No cache associated with object."))

    def action(self):
        "Change the cacheId"
        try:
            cacheId = self.cacheId.getData()
        except WidgetInputError, e:
            #return self.form(errors=e.errors)
            return repr(e.errors)
        else:
            self.cacheable.setCacheId(cacheId)
            return self.form(message=_(u"Saved changes."))


=== Added File Zope3/src/zope/app/cache/browser/cacheableedit.pt ===
<html metal:use-macro="views/standard_macros/page">
  <body>
  <div metal:fill-slot="body">

    <p i18n:translate="">
      This edit form allows you to associate a cache with this object.
    </p>

    <p tal:condition="not: view/current_cache_id" i18n:translate="">
      Currently there is no cache associated with the object.
    </p>
    
    <p tal:condition="view/current_cache_id" i18n:translate="">
      Currently the object uses
      <a tal:omit-tag="not:view/current_cache_url"
         tal:attributes="href view/current_cache_url"
         tal:content="view/current_cache_id"
         i18n:name="cache_id_or_url"/>.
    </p>

    <div tal:condition="python: options.has_key('errors') and
                                options['errors']">
      <span style="font-weight: bold" i18n:translate="">Errors</span>:
      <div tal:repeat="error options/errors | nothing">
        <span tal:replace="python: error[0].title" />:
        <span tal:replace="python: error[1].error_name" />
      </div>
    </div>
    <br />

    <form action="./" method="post" enctype="multipart/form-data">
      <input type="hidden" name="nextURL" value=""
          tal:attributes="value request/URL" />

      <table class="EditTable">
        <tr>
          <th class="EditAttributeName" i18n:translate="">Cache name</th>
          <td class="EditAttributeValue"
              tal:content="structure view/cacheId">
            <input size="20" />
          </td>
        </tr>
      </table>

      <input type="submit" name="ChangeCaching.html:method" value="Save Changes"
             i18n:attributes="value save-changes-button" />
      <input type="submit" name="InvalidateCache.html:method"
             value="Invalidate Cached Value" 
             i18n:attributes="value invalidate-cache-button" />

    </form>
    <div tal:content="options/message|nothing" i18n:translate="" />

  </div>
  </body>

</html>


=== Added File Zope3/src/zope/app/cache/browser/configure.zcml ===
<zope:configure
   xmlns:zope="http://namespaces.zope.org/zope"
   xmlns="http://namespaces.zope.org/browser"
   i18n_domain="zope"
   >

  <addMenuItem
      title="RAM Cache"
      description="A RAM cache is a volatile (in memory) cache for speeding up things"
      class="zope.app.cache.ram.RAMCache"
      permission="zope.ManageServices"
      />

  <pages
      for="zope.app.cache.interfaces.ram.IRAMCache"
      class="zope.app.cache.browser.ram.RAMCacheView"
      permission="zope.Public">
    <page name="editAction.html" attribute="action" />
    <page name="index.html" template="ramedit.pt" 
          menu="zmi_views" title="Edit"/>
    <page name="stats.html" template="ramstats.pt" 
          menu="zmi_views" title="Statistics"/>
  </pages>

</zope:configure>


=== Added File Zope3/src/zope/app/cache/browser/ram.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""RAMCache view

$Id: ram.py,v 1.1 2004/03/01 10:57:35 philikon Exp $
"""
from zope.app.publisher.browser import BrowserView
from zope.app.cache.interfaces.ram import IRAMCache

class RAMCacheView(BrowserView):

    __used_for__ = IRAMCache

    def action(self, maxEntries=None, maxAge=None, cleanupInterval=None):
        self.context.update(maxEntries, maxAge, cleanupInterval)
        self.request.response.redirect('.')


=== Added File Zope3/src/zope/app/cache/browser/ramedit.pt ===
<html metal:use-macro="views/standard_macros/page">
<body>
<div metal:fill-slot="body">

  <p i18n:translate="">You can configure the RAM Cache here.</p>

  <div tal:condition="python: options.has_key('errors') and
                              options['errors']">
    <span style="font-weight: bold" i18n:translate="">Errors</span>:
    <div tal:repeat="error options/errors | nothing">
      <span tal:replace="python: error[0].title" />:
      <span tal:replace="python: error[1].error_name" />
    </div>
  </div>
  <br />

  <form action="./" method="post" enctype="multipart/form-data">
    <table class="EditTable">
      <tr>
        <th class="EditAttributeName" i18n:translate="">
          Maximum cached entries
        </th>
        <td class="EditAttributeValue">
          <input type="text" name="maxEntries:int"   
                 tal:attributes="value context/maxEntries"/>

        </td>
      </tr>
      <tr>
        <th class="EditAttributeName" i18n:translate="">
          Maximum age of cached entries
        </th>
        <td class="EditAttributeValue">
          <input type="text" name="maxAge:int"   
                 tal:attributes="value context/maxAge"/>

        </td>
      </tr>
      <tr>
        <th class="EditAttributeName" i18n:translate="">
          Time between cache cleanups
        </th>
        <td class="EditAttributeValue">
          <input type="text" name="cleanupInterval:int"   
                 tal:attributes="value context/cleanupInterval"/>

        </td>
      </tr>
    </table>

    <input type="submit" name="editAction.html:method" value="Save Changes" 
           i18n:attributes="value save-changes-button" />
    <input type="reset" value="Reset" i18n:attributes="value reset-button" />
  </form>
  <div tal:content="options/message|nothing" i18n:translate=""/>

</div>
</body>

</html>


=== Added File Zope3/src/zope/app/cache/browser/ramstats.pt ===
<html metal:use-macro="views/standard_macros/page">
<body>
<div metal:fill-slot="body">

  <p><span tal:replace="context/zope:name"/> RAMCache statistics</p>

  <div tal:condition="python: options.has_key('errors') and
                              options['errors']">
    <span style="font-weight: bold" i18n:translate="">Errors</span>:
    <div tal:repeat="error options/errors | nothing">
      <span tal:replace="python: error[0].title" />:
      <span tal:replace="python: error[1].error_name" />
    </div>
  </div>
  <br />
  <table  id="sortable" class="listing" summary="Content listing"
         cellpadding="2" cellspacing="0" >
    <thead> 
      <th i18n:translate="">Path</th>
      <th i18n:translate="">Hits</th>
      <th i18n:translate="">Misses</th>
      <th i18n:translate="">Size, bytes</th>
      <th i18n:translate="">Entries</th>
    </thead>
    <tbody>
      <tr tal:repeat="data context/getStatistics">
        <td><span tal:content="data/path">&nbsp;</span></td>
        <td><span tal:content="data/hits">&nbsp;</span></td>
        <td><span tal:content="data/misses">&nbsp;</span></td>
        <td><span tal:content="data/size">&nbsp;</span></td>
        <td><span tal:content="data/entries">&nbsp;</span></td>
      </tr>
    </tbody>
  </table>

  <div tal:content="options/message|nothing" i18n:translate=""/>
</div>
</body>

</html>




More information about the Zope3-Checkins mailing list