-
Notifications
You must be signed in to change notification settings - Fork 14k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement caching and dynamic data fetching. (#1466)
* Rename rv => o in the decorator. * Address comments. * Permissions cleanup: remove none and duplicates. (#1967) * Updates * Rename var and dropdown text * Cleanup * Resolve comments. * Add user to the perm check.
- Loading branch information
Showing
11 changed files
with
306 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from superset import tables_cache | ||
from flask import request | ||
|
||
|
||
def view_cache_key(*unused_args, **unused_kwargs): | ||
args_hash = hash(frozenset(request.args.items())) | ||
return 'view/{}/{}'.format(request.path, args_hash) | ||
|
||
|
||
def memoized_func(timeout=5 * 60, key=view_cache_key): | ||
"""Use this decorator to cache functions that have predefined first arg. | ||
memoized_func uses simple_cache and stored the data in memory. | ||
Key is a callable function that takes function arguments and | ||
returns the caching key. | ||
""" | ||
def wrap(f): | ||
def wrapped_f(cls, *args, **kwargs): | ||
cache_key = key(*args, **kwargs) | ||
o = tables_cache.get(cache_key) | ||
if o is not None: | ||
return o | ||
o = f(cls, *args, **kwargs) | ||
tables_cache.set(cache_key, o, timeout=timeout) | ||
return o | ||
return wrapped_f | ||
return wrap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.