Andriy Kornatskyy avatar Andriy Kornatskyy committed 1a39938

Refactored demo samples due to changed contract of cache dependency.

Comments (0)

Files changed (8)

demos/guestbook/config.py

 import sqlite3
 
 from wheezy.caching.memory import MemoryCache
+from wheezy.caching.patterns import Cached
 from wheezy.html.ext.mako import widget_preprocessor
 from wheezy.web.templates import MakoTemplate
 
 
 cache = MemoryCache()
+cached = Cached(cache, time=15 * 60)
 
 
 def session():

demos/guestbook/views.py

 
 from datetime import timedelta
 
-from wheezy.caching import CacheDependency
 from wheezy.http import CacheProfile
 from wheezy.http.transforms import gzip_transform
 from wheezy.web import handler_cache
 from wheezy.web.handlers import BaseHandler
 from wheezy.web.transforms import handler_transforms
 
-from config import cache
+from config import cached
 from config import session
 from models import Greeting
 from repository import Repository
 from validation import greeting_validator
 
 
-list_cache_dependency = CacheDependency(cache, 'list', time=15 * 60)
-
-
 class ListHandler(BaseHandler):
 
     @handler_cache(CacheProfile('server', duration=timedelta(minutes=15),
             greetings = repo.list_greetings()
         response = self.render_response('list.html',
                                         greetings=greetings)
-        response.dependency = list_cache_dependency
+        response.dependency_key = 'd_list'
         return response
 
 
                 self.error('Sorry, can not add your greeting.')
                 return self.get(greeting)
             db.commit()
-        list_cache_dependency.delete()
+        cached.dependency.delete('d_list')
         return self.see_other_for('list')

demos/template/i18n/en/LC_MESSAGES/membership.po

 msgid "YYYY/MM/DD"
 msgstr "%Y/%m/%d"
 
-#: src/membership/repository/mock.py:69
+#: src/membership/repository/samples.py:19
 msgid "Favorite number"
 msgstr "Favorite number"
 
-#: src/membership/repository/mock.py:70
+#: src/membership/repository/samples.py:20
 msgid "City of birth"
 msgstr "City of birth"
 
-#: src/membership/repository/mock.py:71
+#: src/membership/repository/samples.py:21
 msgid "Favorite color"
 msgstr "Favorite color"
 
-#: src/membership/repository/mock.py:74
+#: src/membership/repository/samples.py:24
 msgid "User"
 msgstr "User"
 
-#: src/membership/repository/mock.py:75
+#: src/membership/repository/samples.py:25
 msgid "Business"
 msgstr "Business"
 
-#: src/membership/service/bridge.py:47 src/membership/service/bridge.py:48
+#: src/membership/service/bridge.py:48
 msgid "The username or password provided is incorrect."
 msgstr "The username or password provided is incorrect."
 
-#: src/membership/service/bridge.py:61 src/membership/service/bridge.py:62
+#: src/membership/service/bridge.py:62
 msgid "The user with such username is already registered. Please try another."
 msgstr "The user with such username is already registered. Please try another."
 
-#: src/membership/service/bridge.py:66 src/membership/service/bridge.py:67
+#: src/membership/service/bridge.py:67
 msgid ""
 "The system was unable to create an account for you. Please try again later."
 msgstr ""
 "The system was unable to create an account for you. Please try again later."
 
-#: src/membership/web/views.py:107 src/membership/web/views.py:125
+#: src/membership/web/views.py:125
 msgid ""
 "Your registration request has been queued. Please wait while your request "
 "will be processed. If your request fails please try again."

demos/template/i18n/membership.po

 msgid "YYYY/MM/DD"
 msgstr "%Y/%m/%d"
 
-#: src/membership/repository/mock.py:69
+#: src/membership/repository/samples.py:19
 msgid "Favorite number"
 msgstr "Favorite number"
 
-#: src/membership/repository/mock.py:70
+#: src/membership/repository/samples.py:20
 msgid "City of birth"
 msgstr "City of birth"
 
-#: src/membership/repository/mock.py:71
+#: src/membership/repository/samples.py:21
 msgid "Favorite color"
 msgstr "Favorite color"
 
-#: src/membership/repository/mock.py:74
+#: src/membership/repository/samples.py:24
 msgid "User"
 msgstr "User"
 
-#: src/membership/repository/mock.py:75
+#: src/membership/repository/samples.py:25
 msgid "Business"
 msgstr "Business"
 
-#: src/membership/service/bridge.py:47 src/membership/service/bridge.py:48
+#: src/membership/service/bridge.py:48
 msgid "The username or password provided is incorrect."
 msgstr "The username or password provided is incorrect."
 
-#: src/membership/service/bridge.py:61 src/membership/service/bridge.py:62
+#: src/membership/service/bridge.py:62
 msgid "The user with such username is already registered. Please try another."
 msgstr "The user with such username is already registered. Please try another."
 
-#: src/membership/service/bridge.py:66 src/membership/service/bridge.py:67
+#: src/membership/service/bridge.py:67
 msgid ""
 "The system was unable to create an account for you. Please try again later."
 msgstr ""
 "The system was unable to create an account for you. Please try again later."
 
-#: src/membership/web/views.py:107 src/membership/web/views.py:125
+#: src/membership/web/views.py:125
 msgid ""
 "Your registration request has been queued. Please wait while your request "
 "will be processed. If your request fails please try again."

demos/template/setup.py

 
 install_requires = [
     'wheezy.core>=0.1.87',
-    'wheezy.caching>=0.1.75',
+    'wheezy.caching>=0.1.80',
     'wheezy.html>=0.1.109',
-    'wheezy.http>=0.1.257',
+    'wheezy.http>=0.1.259',
     'wheezy.routing>=0.1.124',
     'wheezy.security>=0.1.44',
     'wheezy.validation>=0.1.74',

demos/template/src/config.py

 })
 
 # Cache Profiles
-none_cache_profile = CacheProfile(
-    'none',
-    no_store=True,
-    enabled=True)
 static_cache_profile = CacheProfile(
     'public',
     duration=timedelta(minutes=15),

demos/template/src/membership/web/views.py

 from wheezy.core.collections import attrdict
 from wheezy.core.comp import u
 from wheezy.core.descriptors import attribute
+from wheezy.http import none_cache_profile
 from wheezy.security import Principal
 from wheezy.web import handler_cache
 from wheezy.web.handlers import BaseHandler
 
-from config import none_cache_profile
 from factory import Factory
 from membership.models import Credential
 from membership.models import Registration
 and regenerate only when someone added another greeting? Let implement
 this use case with `wheezy.caching`_ package.
 
-Open ``config.py`` and add import for MemoryCache::
+Open ``config.py`` and add import for MemoryCache and Cached::
 
     from wheezy.caching.memory import MemoryCache
 
 and configuration options for HTTP cache middleware)::
 
     cache = MemoryCache()
+    cached = Cached(cache, time=15 * 60)
 
     # HTTPCacheMiddleware
     options.update({
 Let add cache invalidation logic so once user enters a new greeting it cause
 the list page to be refreshed.
 
-In file ``views.py`` add import for ``CacheDependency``::
+In file ``config.py`` add import for ``Cached``::
 
-    from wheezy.caching import CacheDependency
+    from wheezy.caching.patterns import Cached
 
-Declare cache dependency (right after all imports)::
+Declare cached (right after created cache instance)::
 
-    list_cache_dependency = CacheDependency('list', time=15 * 60)
+    cache = MemoryCache()
+    cached = Cached(cache, time=15 * 60)
 
-Modify ``ListHandler`` so it is aware about the list cache dependency::
+Modify ``ListHandler`` so it is aware about the list cache dependency key::
 
     class ListHandler(BaseHandler):
 
                 greetings = repo.list_greetings()
             response = self.render_response('list.html',
                     greetings=greetings)
-            response.dependency = list_cache_dependency
+            response.dependency_key = 'd_list'
             return response
 
 Finally let add a trigger that cause the invalidation to occur in cache.
-Import cache factory from config module::
+Import cached from config module::
 
-    from config import cache
+    from config import cached
 
 Modify ``AddHandler`` so on successful commit the content cache for
 ``ListHandler`` response is invalidated::
         def post(self):
             ...
                 db.commit()
-            list_cache_dependency.delete(cache)
+            cached.dependency.delete('d_list')
             return self.see_other_for('list')
 
 Try run application by issuing the following command::
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.