[Checkins] SVN: zmi.core/trunk/src/zmi/core/cache/ Copy zope.app.cache browser package to zmi.core.
Yusei Tahara
yusei at domen.cx
Sat Aug 8 04:31:34 EDT 2009
Log message for revision 102571:
Copy zope.app.cache browser package to zmi.core.
Changed:
A zmi.core/trunk/src/zmi/core/cache/
A zmi.core/trunk/src/zmi/core/cache/__init__.py
A zmi.core/trunk/src/zmi/core/cache/cacheable.py
A zmi.core/trunk/src/zmi/core/cache/cacheableedit.pt
A zmi.core/trunk/src/zmi/core/cache/configure.zcml
A zmi.core/trunk/src/zmi/core/cache/ram.py
A zmi.core/trunk/src/zmi/core/cache/ramedit.pt
A zmi.core/trunk/src/zmi/core/cache/ramstats.pt
-=-
Added: zmi.core/trunk/src/zmi/core/cache/__init__.py
===================================================================
--- zmi.core/trunk/src/zmi/core/cache/__init__.py (rev 0)
+++ zmi.core/trunk/src/zmi/core/cache/__init__.py 2009-08-08 08:31:33 UTC (rev 102571)
@@ -0,0 +1 @@
+#
Added: zmi.core/trunk/src/zmi/core/cache/cacheable.py
===================================================================
--- zmi.core/trunk/src/zmi/core/cache/cacheable.py (rev 0)
+++ zmi.core/trunk/src/zmi/core/cache/cacheable.py 2009-08-08 08:31:33 UTC (rev 102571)
@@ -0,0 +1,79 @@
+##############################################################################
+#
+# 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.1 (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 89028 2008-07-30 16:35:30Z mgedmin $
+"""
+__docformat__ = 'restructuredtext'
+
+from zope.component import getMultiAdapter
+from zope.publisher.browser import BrowserView
+from zope.annotation.interfaces import IAnnotatable
+
+from zope.app.cache.caching import getCacheForObject, getLocationForCache
+from zope.app.form.utility import setUpEditWidgets
+from zope.i18nmessageid import ZopeMessageFactory as _
+from zope.app.cache.interfaces import ICacheable
+from zope.app.form.interfaces import WidgetInputError
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+
+class CacheableView(BrowserView):
+
+ __used_for__ = IAnnotatable
+
+ form = ViewPageTemplateFile("cacheableedit.pt")
+
+ def __init__(self, *args):
+ super(CacheableView, self).__init__(*args)
+ self.cacheable = ICacheable(self.context)
+ 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."
+ cache = getCacheForObject(self.context)
+ absolute_url = getMultiAdapter((cache, self.request),
+ name='absolute_url')
+ try:
+ return absolute_url()
+ except TypeError:
+ # In case the cache object is a global one and does not have a
+ # location, then we just return None.
+ return None
+
+ def invalidate(self):
+ "Invalidate the current cached value."
+
+ cache = getCacheForObject(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_widget.getInputValue()
+ 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: zmi.core/trunk/src/zmi/core/cache/cacheableedit.pt
===================================================================
--- zmi.core/trunk/src/zmi/core/cache/cacheableedit.pt (rev 0)
+++ zmi.core/trunk/src/zmi/core/cache/cacheableedit.pt 2009-08-08 08:31:33 UTC (rev 102571)
@@ -0,0 +1,58 @@
+<html metal:use-macro="context/@@standard_macros/page"
+ i18n:domain="zope">
+ <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_widget">
+ <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: zmi.core/trunk/src/zmi/core/cache/configure.zcml
===================================================================
--- zmi.core/trunk/src/zmi/core/cache/configure.zcml (rev 0)
+++ zmi.core/trunk/src/zmi/core/cache/configure.zcml 2009-08-08 08:31:33 UTC (rev 102571)
@@ -0,0 +1,23 @@
+<configure
+ xmlns="http://namespaces.zope.org/browser"
+ >
+
+ <addMenuItem
+ title="RAM Cache"
+ description="A RAM cache is a volatile (in memory) cache"
+ class="zope.ramcache.ram.RAMCache"
+ permission="zope.ManageServices"
+ />
+
+ <pages
+ for="zope.ramcache.interfaces.ram.IRAMCache"
+ class="zmi.core.cache.ram.RAMCacheView"
+ permission="zope.ManageServices">
+ <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>
+
+</configure>
Added: zmi.core/trunk/src/zmi/core/cache/ram.py
===================================================================
--- zmi.core/trunk/src/zmi/core/cache/ram.py (rev 0)
+++ zmi.core/trunk/src/zmi/core/cache/ram.py 2009-08-08 08:31:33 UTC (rev 102571)
@@ -0,0 +1,29 @@
+##############################################################################
+#
+# Copyright (c) 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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 102133 2009-07-23 10:09:00Z hannosch $
+"""
+__docformat__ = 'restructuredtext'
+
+from zope.publisher.browser import BrowserView
+from zope.ramcache.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: zmi.core/trunk/src/zmi/core/cache/ramedit.pt
===================================================================
--- zmi.core/trunk/src/zmi/core/cache/ramedit.pt (rev 0)
+++ zmi.core/trunk/src/zmi/core/cache/ramedit.pt 2009-08-08 08:31:33 UTC (rev 102571)
@@ -0,0 +1,61 @@
+<html metal:use-macro="context/@@standard_macros/view"
+ i18n:domain="zope">
+<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: zmi.core/trunk/src/zmi/core/cache/ramstats.pt
===================================================================
--- zmi.core/trunk/src/zmi/core/cache/ramstats.pt (rev 0)
+++ zmi.core/trunk/src/zmi/core/cache/ramstats.pt 2009-08-08 08:31:33 UTC (rev 102571)
@@ -0,0 +1,42 @@
+<html metal:use-macro="context/@@standard_macros/view"
+ i18n:domain="zope">
+<body>
+<div metal:fill-slot="body">
+
+ <p><span tal:replace="context/zope:name"/>
+ <span i18n:translate="">RAMCache statistics</span></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"> </span></td>
+ <td><span tal:content="data/hits"> </span></td>
+ <td><span tal:content="data/misses"> </span></td>
+ <td><span tal:content="data/size"> </span></td>
+ <td><span tal:content="data/entries"> </span></td>
+ </tr>
+ </tbody>
+ </table>
+
+ <div tal:content="options/message|nothing" i18n:translate="" />
+</div>
+</body>
+
+</html>
More information about the Checkins
mailing list