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

Jim Fulton jim@zope.com
Wed, 25 Dec 2002 09:13:59 -0500


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

Added Files:
	__init__.py cacheable.py cacheableedit.pt configure.zcml 
	ram.py ramedit.pt ramstats.pt 
Log Message:
Grand renaming:

- Renamed most files (especially python modules) to lower case.

- Moved views and interfaces into separate hierarchies within each
  project, where each top-level directory under the zope package
  is a separate project.

- Moved everything to src from lib/python.

  lib/python will eventually go away. I need access to the cvs
  repository to make this happen, however.

There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.



=== Zope3/src/zope/app/browser/cache/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:59 2002
+++ Zope3/src/zope/app/browser/cache/__init__.py	Wed Dec 25 09:12:28 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/app/browser/cache/cacheable.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:59 2002
+++ Zope3/src/zope/app/browser/cache/cacheable.py	Wed Dec 25 09:12:28 2002
@@ -0,0 +1,68 @@
+##############################################################################
+#
+# 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$
+"""
+
+from zope.component import getService, getAdapter
+from zope.proxy.context import ContextWrapper
+from zope.publisher.browser import BrowserView
+from zope.schema.interfaces import StopValidation, ValidationError, \
+     ValidationErrorsAll, ConversionErrorsAll
+
+from zope.app.browser.form.widget import Widget
+from zope.app.cache.caching import getCacheForObj, getLocationForCache
+from zope.app.form.utility import setUpEditWidgets
+from zope.app.form.widget import CustomWidget
+from zope.app.interfaces.annotation import IAnnotatable
+from zope.app.interfaces.cache.cache import ICacheable
+from zope.app.interfaces.forms import WidgetInputError
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+
+
+class CacheableView(BrowserView):
+
+    __used_for__ = IAnnotatable
+
+    form = ViewPageTemplateFile("edit.pt")
+
+    def __init__(self, *args):
+        super(CacheableView, self).__init__(*args)
+        self.cachable = getAdapter(self.context, ICacheable)
+        setUpEditWidgets(self, ICacheable, self.cachable)
+
+    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="Invalidated.")
+        else:
+            return self.form(message="No cache associated with object.")
+
+    def action(self):
+        "Change the cacheId"
+        try:
+            cacheId = self.cacheId.getData()
+        except (ValidationErrorsAll, ConversionErrorsAll), e:
+            return self.form(errors=e)
+        except WidgetInputError, e:
+            #return self.form(errors=e.errors)
+            return repr(e.errors)
+        else:
+            self.cachable.setCacheId(cacheId)
+            return self.form(message="Saved changes.")


=== Zope3/src/zope/app/browser/cache/cacheableedit.pt 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:59 2002
+++ Zope3/src/zope/app/browser/cache/cacheableedit.pt	Wed Dec 25 09:12:28 2002
@@ -0,0 +1,42 @@
+<html metal:use-macro="views/standard_macros/page">
+  <body>
+  <div metal:fill-slot="body">
+
+    <p>This edit form allows you to associate a cache with this object.</p>
+
+    <div tal:condition="python: options.has_key('errors') and
+                                options['errors']">
+      <span style="font-weight: bold">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">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" />
+      <input type="submit" name="InvalidateCache.html:method"
+             value="Invalidate Cached Value" />
+
+    </form>
+    <div tal:replace="options/message|nothing" />
+
+  </div>
+  </body>
+
+</html>


=== Zope3/src/zope/app/browser/cache/configure.zcml 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:59 2002
+++ Zope3/src/zope/app/browser/cache/configure.zcml	Wed Dec 25 09:12:28 2002
@@ -0,0 +1,38 @@
+<zopeConfigure
+   xmlns='http://namespaces.zope.org/zope'
+   xmlns:browser='http://namespaces.zope.org/browser'
+>
+
+  <browser:menuItem menu="add_component"
+      for="zope.app.interfaces.container.IAdding"
+      title="RAM Cache" action="RAMCache"
+      description="RAM Cache"/>
+
+  <browser:view for="zope.app.interfaces.cache.ram.IRAMCache"
+		factory="zope.app.browser.cache.ram.RAMCacheView"
+		permission="zope.Public"
+		>
+    <browser:page name="editAction.html" attribute="action" />
+    <browser:page name="index.html"       template="edit.pt" />
+    <browser:page name="stats.html"      template="stats.pt" />
+  </browser:view>
+
+  <browser:menuItems menu="zmi_views"
+     for="zope.app.interfaces.cache.ram.IRAMCache">
+    <browser:menuItem title="Edit"       action="index.html"/>
+    <browser:menuItem title="Statistics" action="stats.html"/>
+  </browser:menuItems>
+
+  <browser:view for="zope.app.interfaces.annotation.IAnnotatable"
+                permission="zope.ManageBindings"
+                factory="zope.app.browser.cache.cacheable.CacheableView">
+
+    <browser:page name="Caching.html"
+                  attribute="form" />
+    <browser:page name="ChangeCaching.html"
+                  attribute="action" />
+    <browser:page name="InvalidateCache.html"
+                  attribute="invalidate" />
+  </browser:view>
+
+</zopeConfigure>


=== Zope3/src/zope/app/browser/cache/ram.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:59 2002
+++ Zope3/src/zope/app/browser/cache/ram.py	Wed Dec 25 09:12:28 2002
@@ -0,0 +1,28 @@
+##############################################################################
+#
+# 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$
+"""
+
+from zope.publisher.browser import BrowserView
+from zope.app.interfaces.cache.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('.')


=== Zope3/src/zope/app/browser/cache/ramedit.pt 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:59 2002
+++ Zope3/src/zope/app/browser/cache/ramedit.pt	Wed Dec 25 09:12:28 2002
@@ -0,0 +1,53 @@
+<html metal:use-macro="views/standard_macros/page">
+  <body>
+  <div metal:fill-slot="body">
+
+    <p>You can configure the RAM Cache here.</p>
+
+    <div tal:condition="python: options.has_key('errors') and
+                                options['errors']">
+      <span style="font-weight: bold">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">Maximum cached entries</th>
+          <td class="EditAttributeValue">
+            <input type="text" name="maxEntries:int"   
+	           tal:attributes="value context/maxEntries"/>
+            
+          </td>
+        </tr>
+        <tr>
+          <th class="EditAttributeName">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">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" />
+      <input type="reset" value="Reset" />
+    </form>
+    <div tal:replace="options/message|nothing" />
+
+  </div>
+  </body>
+
+</html>


=== Zope3/src/zope/app/browser/cache/ramstats.pt 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:59 2002
+++ Zope3/src/zope/app/browser/cache/ramstats.pt	Wed Dec 25 09:12:28 2002
@@ -0,0 +1,40 @@
+<html metal:use-macro="views/standard_macros/page">
+  <body>
+  <div metal:fill-slot="body">
+
+    <p><span tal:replace="context/@@object_name"/> RAMCache statistics</p>
+
+    <div tal:condition="python: options.has_key('errors') and
+                                options['errors']">
+      <span style="font-weight: bold">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>Path</th>
+	  <th>Hits</th>
+	  <th>Misses</th>
+	  <th>Size, bytes</th>
+	  <th>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:replace="options/message|nothing" />
+  </div>
+  </body>
+
+</html>