Disabled cache.
This commit is contained in:
		
							parent
							
								
									21ab5628b0
								
							
						
					
					
						commit
						8486c22c32
					
				| @ -6,5 +6,6 @@ services: | ||||
|       - "8081:8081" | ||||
|     volumes: | ||||
|       - ./:/code | ||||
|     entrypoint: ["python","-m","snek.app"] | ||||
|     entrypoint: ["gunicorn", "-w", "1", "-k", "aiohttp.worker.GunicornWebWorker", "snek.gunicorn:app","--bind","0.0.0.0:8081"] | ||||
|     #["python","-m","snek.app"] | ||||
|     | ||||
| @ -7,6 +7,7 @@ from jinja_markdown2 import MarkdownExtension | ||||
| from snek.system import http | ||||
| from snek.system.middleware import cors_middleware | ||||
| from snek.view.about import AboutHTMLView, AboutMDView | ||||
| from snek.view.docs import DocsHTMLView, DocsMDView | ||||
| from snek.view.index import IndexView | ||||
| from snek.view.login import LoginView | ||||
| from snek.view.login_form import LoginFormView | ||||
| @ -39,6 +40,9 @@ class Application(BaseApplication): | ||||
|         ) | ||||
|         self.router.add_view("/about.html", AboutHTMLView) | ||||
|         self.router.add_view("/about.md", AboutMDView) | ||||
|         self.router.add_view("/docs.html", DocsHTMLView) | ||||
|         self.router.add_view("/docs.md", DocsMDView) | ||||
|          | ||||
|         self.router.add_view("/web.html", WebView) | ||||
|         self.router.add_view("/login.html", LoginView) | ||||
|         self.router.add_view("/login.json", LoginFormView) | ||||
| @ -66,7 +70,7 @@ class Application(BaseApplication): | ||||
|         ) | ||||
|      | ||||
|      | ||||
|     @time_cache_async(60) | ||||
|     #@time_cache_async(60) | ||||
|     async def render_template(self, template, request, context=None): | ||||
|         return await super().render_template(template, request, context) | ||||
| 
 | ||||
|  | ||||
| @ -9,6 +9,7 @@ from pygments.lexers import get_lexer_by_name | ||||
| from pygments.formatters import html | ||||
| from pygments.styles import get_style_by_name | ||||
| import functools | ||||
| from app.cache import time_cache_async | ||||
| 
 | ||||
| class MarkdownRenderer(HTMLRenderer): | ||||
|     def __init__(self, app, template): | ||||
| @ -28,7 +29,6 @@ class MarkdownRenderer(HTMLRenderer): | ||||
|             #return '\n<pre><code>%s</code></pre>\n' % escape(code) | ||||
|         lexer = get_lexer_by_name(lang, stripall=True) | ||||
|         formatter = html.HtmlFormatter(lineseparator="<br>") | ||||
|         print(code, lang,info, flush=True) | ||||
|         return highlight(code, lexer, formatter) | ||||
|     def render(self): | ||||
|         markdown_string = self.app.template_path.joinpath(self.template).read_text() | ||||
| @ -37,11 +37,12 @@ class MarkdownRenderer(HTMLRenderer): | ||||
|         return markdown(markdown_string) | ||||
| 
 | ||||
| 
 | ||||
| @functools.cache | ||||
| 
 | ||||
| def render_markdown_sync(app, markdown_string): | ||||
|     renderer = MarkdownRenderer(app,None) | ||||
|     markdown = Markdown(renderer=renderer) | ||||
|     return markdown(markdown_string) | ||||
| 
 | ||||
| @time_cache_async(120) | ||||
| async def render_markdown(app, markdown_string): | ||||
|      return render_markdown_sync(app,markdown_string) | ||||
| @ -14,56 +14,3 @@ I made several design choices: | ||||
|  - !DRY for HMTL/jinja2 templates. For templates Snek does prefer to repeat itself to implement exceptions for a page easier. For Snek it's preffered do a few updates instead of maintaining a complex generic system that requires maintenance regarding templates. | ||||
|  - No existing chat backend like `inspircd` (Popular decent IRC server written in the language of angels) because I prefer to know what is exactly going on above performance and concurrency limit. Also, this approach reduces as networking layer / gateway layer. | ||||
| 
 | ||||
| # Some internals | ||||
| 
 | ||||
| A few examples of how the system framework works. | ||||
| 
 | ||||
| ## How to create a user | ||||
| ```python | ||||
| # Save user to the table named 'user' | ||||
| # Password gets sha256 encrypted with default a salt string | ||||
| # of the snek.system.security module. | ||||
| 
 | ||||
| new_user_object = await app.service.user.register( | ||||
|     username="retoor",  | ||||
|     password="retoorded" | ||||
| ) | ||||
| ``` | ||||
| 
 | ||||
| ## Encrypt string | ||||
| ```python | ||||
| from snek.system import security | ||||
| 
 | ||||
| # Support for both utf and bytes. | ||||
| var1 = security.encrypt("data") | ||||
| var2 = security.encrypt(b"data") | ||||
| 
 | ||||
| # Is correct: | ||||
| assert(var1 == var2) | ||||
| ``` | ||||
| 
 | ||||
| ## How to create a basic HTML / Markdown view | ||||
| ```python | ||||
| from snek.system.view import BaseView  | ||||
| 
 | ||||
| class IndexView(BaseView): | ||||
|      | ||||
|     async def get(self): | ||||
|         # The render function supports markdown. | ||||
|         # It will render with syntax highlighting. | ||||
|         # Just use the .md file extension in the file name. | ||||
|         return await self.render("index.html") | ||||
| ``` | ||||
| ## How to create a FormView | ||||
| ```python | ||||
| from snek.system.view import BaseFormView | ||||
| from snek.form.register import RegisterForm | ||||
| 
 | ||||
| class RegisterFormView(BaseFormView): | ||||
|      | ||||
|     form = RegisterForm | ||||
| ``` | ||||
| ## How to register a class view | ||||
| ```python | ||||
| app.routes.add_view("/your-page.html", YourViewClass) | ||||
| ``` | ||||
| @ -15,7 +15,8 @@ | ||||
|     <span style="padding:10px;">Or</span> | ||||
|     <fancy-button url="/register.html" text="Register"></fancy-button> | ||||
|     <a href="/about.html">Design choices</a> | ||||
|     <a href="/web.html">See web Application so far</a> | ||||
|     <a href="/web.html">App preview</a> | ||||
|     <a href="/docs.html">API docs</a> | ||||
|   </div> | ||||
| </body> | ||||
| </html> | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user