{ "info": { "author": "William Laroche", "author_email": "william.laroche@tackv.ca", "bugtrack_url": null, "classifiers": [], "description": "# Simple Memory Cache\n\nA dead simple memory cache to allow a variable to easily be lazy-loaded when needed. \nOnly 43 lines of code and no dependencies.\n\nThis module is used by our SpinHub App (https://www.spinhub.ca) which is currently in development. It allows us to in-memory cache variables for re-use in successful AWS Lambda function executions.\n\n## Use-case 1: Caching responses\n\nA specific use case for us is to cache de JWKS (the JSON Web Key Set) of our Auth0 domain:\n\n```python\n\nimport requests\nfrom simple_memory_cache import GLOBAL_CACHE\n\nAUTH0_DOMAIN = 'mysubdomain.auth0.com'\n\nJWKS_URL = AUTH0_DOMAIN + '/.well-known/jwks.json'\n\njwks_var = GLOBAL_CACHE.MemoryCachedVar('jwks')\n\n@jwks.on_first_access\ndef _retrieve_jwks():\n return requests.get(JWKS_URL).json()\n\ndef do_something():\n\n # First call will trigger _retrieve_jwks and store the return value.\n # If this is called within the same AWS Lambda instance, the global context will still be there\n # and the value will simply be returned\n jwks = jwks_var.get() \n\n try:\n (validate JWT token w/ jwks)\n except (ValidationError):\n # On a validation error, Auth0 recommends to refetch the JWKS in case it changed.\n # We invalidate the value and get it once again.\n jwks_var.invalidate()\n jwks = jwks_var.get()\n (validate JWT token w/ jwks)\n\n```\n\n## Use-case 2: Specific Implementation for Flask Globals\n\nWe often encounter the case where we wish to set a Flask g member only if it is not set.\nYou can create your own MemoryCachedVar adapted to this case in 5 lines of code:\n\n```python\n\nfrom simple_memory_cache import CachedVar, NO_VALUE_STORED\n\nfrom flask import g, request\n\nclass FlaskGCache(CachedVar):\n def _get_stored_value(self):\n return getattr(g, self.name, NO_VALUE_STORED)\n\n def _set_stored_value(self, value):\n setattr(g, self.name, value) \n\n\napp = (...)\n\nuser_var = FlaskGCache('user')\n\n@user_var.on_first_access\ndef retrieve_user_from_request():\n token = request.headers.get('Authorization', None)\n # ... Decode token or raise Unauthorized\n return user\n\n@app.route()\ndef private_route():\n user = user_var.get() # Authorizes the user once, will raise Unauthorized if unable.\n # ...\n user = user_var.get() # Simply returns the value stored in g.user\n\n```\n\n# Creators\n\nCreated by Tack Verification, a company dedicated to reducing operational costs related to hardware systems verification. \nhttps://www.tackv.ca\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/tackv/simple-memory-cache", "keywords": "", "license": "", "maintainer": "William Laroche", "maintainer_email": "william.laroche@tackv.ca", "name": "simple-memory-cache", "package_url": "https://pypi.org/project/simple-memory-cache/", "platform": "", "project_url": "https://pypi.org/project/simple-memory-cache/", "project_urls": { "Homepage": "https://gitlab.com/tackv/simple-memory-cache" }, "release_url": "https://pypi.org/project/simple-memory-cache/1.0.0/", "requires_dist": null, "requires_python": "", "summary": "Dead Simple Memory Cache", "version": "1.0.0", "yanked": false, "yanked_reason": null }, "last_serial": 6025099, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "dc1c71df6d22673864d1b86cfbecabec", "sha256": "4a956c98408e63b04e06d2601123a8cb039217d0981cdcd79e0e083282cbb639" }, "downloads": -1, "filename": "simple_memory_cache-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "dc1c71df6d22673864d1b86cfbecabec", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3981, "upload_time": "2019-10-24T17:41:30", "upload_time_iso_8601": "2019-10-24T17:41:30.016444Z", "url": "https://files.pythonhosted.org/packages/52/bf/59104c2827924a2505e19b2df906ede2728283f6c81729f5b5e78d7d2fbe/simple_memory_cache-1.0.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "9f70e62e228e2a4afa974a97dd8883a3", "sha256": "97e1780001ef3117fe53c6012a4913a915007520e05e2120373725eff0041c2e" }, "downloads": -1, "filename": "simple_memory_cache-1.0.0.tar.gz", "has_sig": false, "md5_digest": "9f70e62e228e2a4afa974a97dd8883a3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3004, "upload_time": "2019-10-24T17:41:32", "upload_time_iso_8601": "2019-10-24T17:41:32.347607Z", "url": "https://files.pythonhosted.org/packages/e0/a4/3f35ba91bb93eb3018a6d3cd4582e4d7ca48a0e8ba9f6f595086c1f9bfe7/simple_memory_cache-1.0.0.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "dc1c71df6d22673864d1b86cfbecabec", "sha256": "4a956c98408e63b04e06d2601123a8cb039217d0981cdcd79e0e083282cbb639" }, "downloads": -1, "filename": "simple_memory_cache-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "dc1c71df6d22673864d1b86cfbecabec", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3981, "upload_time": "2019-10-24T17:41:30", "upload_time_iso_8601": "2019-10-24T17:41:30.016444Z", "url": "https://files.pythonhosted.org/packages/52/bf/59104c2827924a2505e19b2df906ede2728283f6c81729f5b5e78d7d2fbe/simple_memory_cache-1.0.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "9f70e62e228e2a4afa974a97dd8883a3", "sha256": "97e1780001ef3117fe53c6012a4913a915007520e05e2120373725eff0041c2e" }, "downloads": -1, "filename": "simple_memory_cache-1.0.0.tar.gz", "has_sig": false, "md5_digest": "9f70e62e228e2a4afa974a97dd8883a3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3004, "upload_time": "2019-10-24T17:41:32", "upload_time_iso_8601": "2019-10-24T17:41:32.347607Z", "url": "https://files.pythonhosted.org/packages/e0/a4/3f35ba91bb93eb3018a6d3cd4582e4d7ca48a0e8ba9f6f595086c1f9bfe7/simple_memory_cache-1.0.0.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }