Example #1
0
    def _setConnectionName(self, name):
        self._connectionName = name
        cache = getCacheForObject(self)
        location = getLocationForCache(self)

        if cache and location:
            cache.invalidate(location)
Example #2
0
    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."))
Example #3
0
    def __call__(self, **kw):
        """See zope.app.rdb.interfaces"""

        # Try to resolve arguments
        arg_values = {}
        missing = []
        for name in self._arguments.keys():
            name = name.encode('UTF-8')
            try:
                # Try to find argument in keywords
                arg_values[name] = kw[name]
            except KeyError:
                # Okay, the first try failed, so let's try to find the default
                arg = self._arguments[name]
                try:
                    arg_values[name] = arg['default']
                except KeyError:
                    # Now the argument might be optional anyways; let's check
                    try:
                        if not arg['optional']:
                            missing.append(name)
                    except KeyError:
                        missing.append(name)

        try:
            connection = self.getConnection()
        except KeyError:
            raise AttributeError("The database connection '%s' cannot be "
                                 "found." % (self.connectionName))

        query = apply(self.template, (), arg_values)
        cache = getCacheForObject(self)
        location = getLocationForCache(self)
        if cache and location:
            _marker = object()
            result = cache.query(location, {'query': query}, default=_marker)
            if result is not _marker:
                return result
        result = queryForResults(connection, query)
        if cache and location:
            cache.set(result, location, {'query': query})
        return result
Example #4
0
 def testGetLocationForCache(self):
     obj = ObjectStub()
     self.assertEqual(getLocationForCache(obj), '/cached-object')