[Zope3-checkins] CVS: Zope3/src/zope/app/browser/cache - __init__.py:1.1.2.1 cacheable.py:1.1.2.1 cacheableedit.pt:1.1.2.1 configure.zcml:1.1.2.1 ram.py:1.1.2.1 ramedit.pt:1.1.2.1 ramstats.pt:1.1.2.1
Jim Fulton
jim@zope.com
Mon, 23 Dec 2002 14:31:02 -0500
Update of /cvs-repository/Zope3/src/zope/app/browser/cache
In directory cvs.zope.org:/tmp/cvs-serv19908/zope/app/browser/cache
Added Files:
Tag: NameGeddon-branch
__init__.py cacheable.py cacheableedit.pt configure.zcml
ram.py ramedit.pt ramstats.pt
Log Message:
Initial renaming before debugging
=== Added File Zope3/src/zope/app/browser/cache/__init__.py ===
#
# This file is necessary to make this directory a package.
=== Added File Zope3/src/zope/app/browser/cache/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.2.1 2002/12/23 19:31:00 jim Exp $
"""
from zope.app.interfaces.cache.cache import ICacheable
from zope.app.interfaces.annotation import IAnnotatable
from zope.app.cache.caching import getCacheForObj, getLocationForCache
from Zope.App.PageTemplate import ViewPageTemplateFile
from zope.publisher.browser import BrowserView
from zope.app.form.widget import CustomWidget
from Zope.App.Forms.Views.Browser import Widget
from zope.component import getService, getAdapter
from zope.proxy.context.context import ContextWrapper
from zope.schema.interfaces import StopValidation, ValidationError, \
ValidationErrorsAll, ConversionErrorsAll
from zope.app.interfaces.forms import WidgetInputError
from zope.app.form.utility import setUpEditWidgets
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.")
=== Added File Zope3/src/zope/app/browser/cache/cacheableedit.pt ===
<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>
=== Added File Zope3/src/zope/app/browser/cache/configure.zcml ===
<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:defaultView for="zope.app.interfaces.cache.ram.IRAMCache"
name="edit.html" />
<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="edit.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="edit.html"/>
<browser:menuItem title="Statistics" action="stats.html"/>
</browser:menuItems>
</zopeConfigure>
<zopeConfigure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser='http://namespaces.zope.org/browser'
>
<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>
=== Added File Zope3/src/zope/app/browser/cache/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.2.1 2002/12/23 19:31:00 jim Exp $
"""
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('.')
=== Added File Zope3/src/zope/app/browser/cache/ramedit.pt ===
<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>
=== Added File Zope3/src/zope/app/browser/cache/ramstats.pt ===
<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"> </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:replace="options/message|nothing" />
</div>
</body>
</html>