{"id":24623024,"url":"https://github.com/cdent/tiddlywebplugins.fastly","last_synced_at":"2025-03-19T01:14:38.589Z","repository":{"id":10585044,"uuid":"12795280","full_name":"cdent/tiddlywebplugins.fastly","owner":"cdent","description":"TiddlyWeb Plugin for using Fastly as a dynamic caching accelerator","archived":false,"fork":false,"pushed_at":"2013-09-25T22:07:47.000Z","size":286,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T03:28:52.315Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cdent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-09-12T21:28:07.000Z","updated_at":"2017-02-16T07:11:35.000Z","dependencies_parsed_at":"2022-09-02T15:02:01.630Z","dependency_job_id":null,"html_url":"https://github.com/cdent/tiddlywebplugins.fastly","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdent%2Ftiddlywebplugins.fastly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdent%2Ftiddlywebplugins.fastly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdent%2Ftiddlywebplugins.fastly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdent%2Ftiddlywebplugins.fastly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cdent","download_url":"https://codeload.github.com/cdent/tiddlywebplugins.fastly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244333022,"owners_count":20436123,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-25T03:14:02.598Z","updated_at":"2025-03-19T01:14:38.571Z","avatar_url":"https://github.com/cdent.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# What\n\n`tiddlywebplugins.fastly` is a [TiddlyWeb](http://tiddlyweb.com/)\nplugin that works with the [Fastly](http://fastly.com) dynamic CDN to\neffectively cache single\n[recipes](http://tiddlyweb.tiddlyspace.com/recipe),\n[bags](http://tiddlyweb.tiddlyspace.com/bag), [tiddlers](http://tiddlyweb.tiddlyspace.comtiddler) and collections thereof.\n\nSee [the design notes](DESIGNNOTES.md) for background info.\n\nThis plugin is an experiment to explore what hurdles need to be\novercome to get TiddlyWeb working in the Fastly context and generally\nto explore the Fastly ecosystem.\n\n# Why\n\nFor fast.\n\nDepending on the usage profile (the ratio of reads to writes) of the\nTiddlyWeb service the number of hits against the backend will drop\n_dramatically_ and the effective latency for the end user will be\nsignificantly improved. This means the backend can be quite\nlightweight while still providing zoom to the users.\n\n# How \n\nAn existing TiddlyWeb\n[instance](http://tiddlyweb.tiddlyspace.com/instance) can be updated\nto use this plugin as follows (*note*: The second step is not yet true\nas the plugin has not been released to PyPI yet, please clone this\nrepo and install from there):\n\n* Install [fastly-py](https://github.com/fastly/fastly-py).\n* Install the plugin: `pip install -U tiddlywebplugins.fastly`.\n* Edit\n  [tiddlywebconfig.py](http://tiddlyweb.tiddlyspace.com/tiddlywebconfig.py)\n  to add `tiddlywebplugins.fastly` to\n  [system_plugins](http://tiddlyweb.tiddlyspace.com/system_plugins)\n  and\n  [twanager_plugins](http://tiddlyweb.tiddlyspace.com/twanager_plugins) and\n  add keys and values for `fastly.server_id` and `fastly.api_key`\n  (found in the analytics and configuration app at\n  \u003chttp://fastly.com/\u003e:\n\n\n        'system_plugins': ['tiddlywebwiki', 'tiddlywebwplugins.fastly'],\n        'twanager_plugins': ['tiddlywebwiki', 'tiddlywebwplugins.fastly'],\n        'fastly.server_id': 'your_server_id',\n        'fastly.api_key': 'your_api_key'\n\n* Restart the instance.\n\nOnce installed three new pieces of functionality will be present:\n\n* There are several new\n  [twanager](http://tiddlyweb.tiddlyspace.com/twanager) commands for\n  inspecting and manipulating the Fastly configuration and manually\n  purging URLs and keys. Run `twanager` to see them listed.\n* Outgoing responses to `GET` requests are augmented with appropriate\n  `Surrogate-Key` headers.\n* When entities are written to the store (via `store.put`) a `HOOK`\n  sends a `purge_key` request to the Fastly API.\n\n# Non-Caching URIs\n\nBy default Fastly will cache anything you give it. If you need to\navoid this you can write custom VCL for various rules that will cause\na `pass`. One convenient catch-all is to `pass` on anything which has\nnot provided a `Surrogate-Key` header:\n\n```\n    if ( !beresp.http.surrogate-key ) { \n        set beresp.ttl = 0s;\n        set beresp.grace = 0s;\n        return(pass);\n    }\n```\n\nThis, however, is a sledgehammer. It is generally better to let most\nURIs cache and configure `pass` on specific URIs.\n\n# Custom URI Handlers\n\nThe code for surrogate keys can be extended to generate keys for\ncustom routes provided by plugins. For example to generate keys for\nthe friendlywiki route provided by\n[tiddlywebwiki](https://pypi.python.org/pypi/tiddlywebwiki) a plugin\nwith the following code could be used:\n\n```\nfrom tiddlywebplugins.fastly.surrogates import recipe_tiddlers_uri_keys\n\ndef init(config):\n    def friendly_keys(environ, start_response):\n        return recipe_tiddlers_uri_keys(environ)\n\n    config['fastly.selector'].add('/{recipe_name:segment}', GET=friendly_keys)\n```\n\nThis is a hack to utilize the WSGI dispatching routines in\n[Selector](https://pypi.python.org/pypi/selector) to call a function\nwhich returns a list of keys. The function should return whatever keys\nmake sense for the given route. In this example since the route\nreturns a collection of tiddlers generated by a recipe the\n`recipe_tiddlers_uri_keys` method is used.\n\n# Caveats\n\nAt this time the plugin is not fully complete: Authenticated scenarios\nare not handled. See the [design notes](DESIGNNOTES.md) for comments on\nauthentication.\n\nIf you need a quick fix for dealing with Auth you can add cookies to\nthe request hash. This will create a per user cache. See:\n\n* [How do I change the hash\n  key](https://fastly.zendesk.com/entries/23686118-How-do-I-change-what-the-cache-key-is-defined-as-)\n* [Caching even when cookies are\n  present](https://www.varnish-cache.org/trac/wiki/VCLExampleCacheCookies#Addingthecookietothehash)\n* [Issue #2](https://github.com/cdent/tiddlywebplugins.fastly/issues/2)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdent%2Ftiddlywebplugins.fastly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcdent%2Ftiddlywebplugins.fastly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdent%2Ftiddlywebplugins.fastly/lists"}