blob: 08cd6b38bbbe955024c591b8e7d124ce6cde9b52 [file] [log] [blame]
{"version":3,"sources":["webpack:///./src/pages/docs/installation/caching.mdx"],"names":["_frontmatter","layoutProps","MDXLayout","DefaultLayout","MDXContent","components","props","mdxType","parentName","isMDXComponent"],"mappings":"wPAQaA,G,UAAe,S,yNAC5B,IAAMC,EAAc,CAClBD,gBAEIE,EAAYC,IACH,SAASC,EAAT,GAGZ,IAFDC,EAEC,EAFDA,WACGC,EACF,8BACD,OAAO,YAACJ,EAAD,eAAeD,EAAiBK,EAAhC,CAAuCD,WAAYA,EAAYE,QAAQ,cAG5E,iBAAQ,CACN,GAAM,WADR,WAGA,sCAAqB,6BAAGC,WAAW,KAAQ,CACvC,KAAQ,0CADS,iBAArB,kHAGgE,0BAAYA,WAAW,KAAvB,gBAHhE,4DAIqB,0BAAYA,WAAW,KAAvB,qBAJrB,gFAKK,0BAAYA,WAAW,KAAvB,mBALL,SAK0E,6BAAGA,WAAW,KAAQ,CAC5F,KAAQ,4CAD8D,4BAL1E,iBAQA,oEAAmD,0BAAYA,WAAW,KAAvB,gBAAnD,QAAoH,0BAAYA,WAAW,KAAvB,qBAApH,aACF,0BAAYA,WAAW,KAAvB,sBADE,uBACoF,6BAAGA,WAAW,KAAQ,CACtG,KAAQ,8EADwE,oCADpF,KAIA,wJAEA,sBACE,kBAAIA,WAAW,MAAf,iCAAsD,6BAAGA,WAAW,MAAS,CACzE,KAAQ,sCAD0C,WAAtD,uBAGJ,0BAAYA,WAAW,MAAvB,oBAHI,mDAIA,kBAAIA,WAAW,MAAf,2BAAgD,6BAAGA,WAAW,MAAS,CACnE,KAAQ,uCADoC,SAAhD,oBAIF,4EACA,kNAES,0BAAYA,WAAW,KAAvB,qBAFT,KAGA,uBAAK,gCAAMA,WAAW,OAAU,IAA3B,kOAOL,sEAAqD,6BAAGA,WAAW,KAAQ,CACvE,KAAQ,0EADyC,QAArD,mBAGA,gKACkC,0BAAYA,WAAW,KAAvB,uBADlC,eACiH,0BAAYA,WAAW,KAAvB,aADjH,KAEA,uBAAK,gCAAMA,WAAW,OAAU,CAC5B,UAAa,oBADZ,oTAcL,yIACoB,0BAAYA,WAAW,KAAvB,2BADpB,UAEA,iBAAQ,CACN,GAAM,sBADR,sBAGA,qHACA,uBAAK,gCAAMA,WAAW,OAAU,IAA3B,4FAKL,8KAEA,kFACA,uBAAK,gCAAMA,WAAW,OAAU,CAC5B,UAAa,oBADZ,0oBAyBL,kFAAiE,0BAAYA,WAAW,KAAvB,mCAAjE,wDAEA,uBAAK,gCAAMA,WAAW,OAAU,IAA3B,yDAEL,qFAAoE,0BAAYA,WAAW,KAAvB,2BAApE,kGACkF,0BAAYA,WAAW,KAAvB,eADlF,uEAGA,uBAAK,gCAAMA,WAAW,OAAU,CAC5B,UAAa,oBADZ,+EAKL,+CACA,uBAAK,gCAAMA,WAAW,OAAU,IAA3B,8C,uNAMTJ,EAAWK,gBAAiB","file":"component---src-pages-docs-installation-caching-mdx-6a5053d460ce88818cc0.js","sourcesContent":["import * as React from 'react'\n /* @jsx mdx */\nimport { mdx } from '@mdx-js/react';\n/* @jsxRuntime classic */\n\n/* @jsx mdx */\n\nimport DefaultLayout from \"/home/runner/work/superset/superset/docs/node_modules/gatsby-theme-docz/src/base/Layout.js\";\nexport const _frontmatter = {};\nconst layoutProps = {\n _frontmatter\n};\nconst MDXLayout = DefaultLayout;\nexport default function MDXContent({\n components,\n ...props\n}) {\n return <MDXLayout {...layoutProps} {...props} components={components} mdxType=\"MDXLayout\">\n\n\n <h2 {...{\n \"id\": \"caching\"\n }}>{`Caching`}</h2>\n <p>{`Superset uses `}<a parentName=\"p\" {...{\n \"href\": \"https://flask-caching.readthedocs.io/\"\n }}>{`Flask-Caching`}</a>{` for caching purpose. For security reasons,\nthere are two separate cache configs for Superset's own metadata (`}<inlineCode parentName=\"p\">{`CACHE_CONFIG`}</inlineCode>{`) and charting data queried from\nconnected datasources (`}<inlineCode parentName=\"p\">{`DATA_CACHE_CONFIG`}</inlineCode>{`). However, Query results from SQL Lab are stored in another backend\ncalled `}<inlineCode parentName=\"p\">{`RESULTS_BACKEND`}</inlineCode>{`, See `}<a parentName=\"p\" {...{\n \"href\": \"/docs/installation/async-queries-celery\"\n }}>{`Async Queries via Celery`}</a>{` for details.`}</p>\n <p>{`Configuring caching is as easy as providing `}<inlineCode parentName=\"p\">{`CACHE_CONFIG`}</inlineCode>{` and `}<inlineCode parentName=\"p\">{`DATA_CACHE_CONFIG`}</inlineCode>{` in your\n`}<inlineCode parentName=\"p\">{`superset_config.py`}</inlineCode>{` that complies with `}<a parentName=\"p\" {...{\n \"href\": \"https://flask-caching.readthedocs.io/en/latest/#configuring-flask-caching\"\n }}>{`the Flask-Caching specifications`}</a>{`.`}</p>\n <p>{`Flask-Caching supports various caching backends, including Redis, Memcached, SimpleCache (in-memory), or the\nlocal filesystem.`}</p>\n <ul>\n <li parentName=\"ul\">{`Memcached: we recommend using `}<a parentName=\"li\" {...{\n \"href\": \"https://pypi.org/project/pylibmc/\"\n }}>{`pylibmc`}</a>{` client library as\n`}<inlineCode parentName=\"li\">{`python-memcached`}</inlineCode>{` does not handle storing binary data correctly.`}</li>\n <li parentName=\"ul\">{`Redis: we recommend the `}<a parentName=\"li\" {...{\n \"href\": \"https://pypi.python.org/pypi/redis\"\n }}>{`redis`}</a>{` Python package`}</li>\n </ul>\n <p>{`Both of these libraries can be installed using pip.`}</p>\n <p>{`For chart data, Superset goes up a “timeout search path”, from a slice's configuration\nto the datasource’s, the database’s, then ultimately falls back to the global default\ndefined in `}<inlineCode parentName=\"p\">{`DATA_CACHE_CONFIG`}</inlineCode>{`.`}</p>\n <pre><code parentName=\"pre\" {...{}}>{`DATA_CACHE_CONFIG = {\n 'CACHE_TYPE': 'redis',\n 'CACHE_DEFAULT_TIMEOUT': 60 * 60 * 24, # 1 day default (in secs)\n 'CACHE_KEY_PREFIX': 'superset_results',\n 'CACHE_REDIS_URL': 'redis://localhost:6379/0',\n}\n`}</code></pre>\n <p>{`Custom cache backends are also supported. See `}<a parentName=\"p\" {...{\n \"href\": \"https://flask-caching.readthedocs.io/en/latest/#custom-cache-backends\"\n }}>{`here`}</a>{` for specifics.`}</p>\n <p>{`Superset has a Celery task that will periodically warm up the cache based on different strategies.\nTo use it, add the following to the `}<inlineCode parentName=\"p\">{`CELERYBEAT_SCHEDULE`}</inlineCode>{` section in `}<inlineCode parentName=\"p\">{`config.py`}</inlineCode>{`:`}</p>\n <pre><code parentName=\"pre\" {...{\n \"className\": \"language-python\"\n }}>{`CELERYBEAT_SCHEDULE = {\n 'cache-warmup-hourly': {\n 'task': 'cache-warmup',\n 'schedule': crontab(minute=0, hour='*'), # hourly\n 'kwargs': {\n 'strategy_name': 'top_n_dashboards',\n 'top_n': 5,\n 'since': '7 days ago',\n },\n },\n}\n`}</code></pre>\n <p>{`This will cache all the charts in the top 5 most popular dashboards every hour. For other\nstrategies, check the `}<inlineCode parentName=\"p\">{`superset/tasks/cache.py`}</inlineCode>{` file.`}</p>\n <h3 {...{\n \"id\": \"caching-thumbnails\"\n }}>{`Caching Thumbnails`}</h3>\n <p>{`This is an optional feature that can be turned on by activating it’s feature flag on config:`}</p>\n <pre><code parentName=\"pre\" {...{}}>{`FEATURE_FLAGS = {\n \"THUMBNAILS\": True,\n \"THUMBNAILS_SQLA_LISTENERS\": True,\n}\n`}</code></pre>\n <p>{`For this feature you will need a cache system and celery workers. All thumbnails are store on cache\nand are processed asynchronously by the workers.`}</p>\n <p>{`An example config where images are stored on S3 could be:`}</p>\n <pre><code parentName=\"pre\" {...{\n \"className\": \"language-python\"\n }}>{`from flask import Flask\nfrom s3cache.s3cache import S3Cache\n\n...\n\nclass CeleryConfig(object):\n BROKER_URL = \"redis://localhost:6379/0\"\n CELERY_IMPORTS = (\"superset.sql_lab\", \"superset.tasks\", \"superset.tasks.thumbnails\")\n CELERY_RESULT_BACKEND = \"redis://localhost:6379/0\"\n CELERYD_PREFETCH_MULTIPLIER = 10\n CELERY_ACKS_LATE = True\n\n\nCELERY_CONFIG = CeleryConfig\n\ndef init_thumbnail_cache(app: Flask) -> S3Cache:\n return S3Cache(\"bucket_name\", 'thumbs_cache/')\n\n\nTHUMBNAIL_CACHE_CONFIG = init_thumbnail_cache\n# Async selenium thumbnail task will use the following user\nTHUMBNAIL_SELENIUM_USER = \"Admin\"\n`}</code></pre>\n <p>{`Using the above example cache keys for dashboards will be `}<inlineCode parentName=\"p\">{`superset_thumb__dashboard__{ID}`}</inlineCode>{`. You can\noverride the base URL for selenium using:`}</p>\n <pre><code parentName=\"pre\" {...{}}>{`WEBDRIVER_BASEURL = \"https://superset.company.com\"\n`}</code></pre>\n <p>{`Additional selenium web drive configuration can be set using `}<inlineCode parentName=\"p\">{`WEBDRIVER_CONFIGURATION`}</inlineCode>{`. You can\nimplement a custom function to authenticate selenium. The default function uses the `}<inlineCode parentName=\"p\">{`flask-login`}</inlineCode>{`\nsession cookie. Here's an example of a custom function signature:`}</p>\n <pre><code parentName=\"pre\" {...{\n \"className\": \"language-python\"\n }}>{`def auth_driver(driver: WebDriver, user: \"User\") -> WebDriver:\n pass\n`}</code></pre>\n <p>{`Then on configuration:`}</p>\n <pre><code parentName=\"pre\" {...{}}>{`WEBDRIVER_AUTH_FUNC = auth_driver\n`}</code></pre>\n\n </MDXLayout>;\n}\n;\nMDXContent.isMDXComponent = true;\n "],"sourceRoot":""}