Alessandro Molina avatar Alessandro Molina committed f282078

Add article view caching support and increase datahelpers dependency to avoid issues with attachments

Comments (0)

Files changed (3)

     "TurboGears2 >= 2.1.4",
     "tgext.pluggable >= 0.1.0",
     "tgext.tagging >= 0.2.1",
-    "tgext.datahelpers",
+    "tgext.datahelpers >= 0.0.9",
     "tgext.crud >= 0.4"
-    version='0.5.5',
+    version='0.5.6',
     description='Pluggable Minimalistic Blog for TurboGears2 with Attachments and Tags',
     author='Alessandro Molina',


         for func in hooks:
             func(article, kw)
-        return dict(article=article)
+        return dict(article=article,
+                    tg_cache=article.caching_options)


     sqla_events = False
 AttachmentType = tg.config.get('_smallpress',{}).get('attachment_type', AttachedFile)
+ENABLE_ARTICLES_CACHE = tg.config.get('_smallpress',{}).get('enable_cache', False)
 class Blog(DeclarativeBase):
     __tablename__ = 'smallpress_blogs'
         return identity['user'] ==
+    @property
+    def caching_options(self):
+        if not ENABLE_ARTICLES_CACHE:
+            return dict()
+        userid = request.identity['user'].user_id if request.identity else 'None'
+        try:
+            return dict(key='%s-%s-%s-%s' % (userid, 'smallpress-article',
+                                             self.uid, self.update_date.strftime('%Y-%m-%d-%H-%M-%S')),
+                                             expire=14400, type="memory")
+        except (IndexError, ValueError):
+            return dict()
 if whoosh_enabled and sqla_events:
     event.listen(Article, 'after_update', Article.after_update)
     event.listen(Article, 'after_insert', Article.after_insert)
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
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.