Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-codegen
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Christian Heinigk
dune-codegen
Commits
fffca594
Commit
fffca594
authored
9 years ago
by
Dominic Kempf
Browse files
Options
Downloads
Patches
Plain Diff
Define a cache context that allows to temporarily add global tags
parent
a82b2b6b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
python/dune/perftool/generation/__init__.py
+2
-1
2 additions, 1 deletion
python/dune/perftool/generation/__init__.py
python/dune/perftool/generation/cache.py
+33
-0
33 additions, 0 deletions
python/dune/perftool/generation/cache.py
with
35 additions
and
1 deletion
python/dune/perftool/generation/__init__.py
+
2
−
1
View file @
fffca594
from
__future__
import
absolute_import
from
dune.perftool.generation.cache
import
(
generator_factory
,
from
dune.perftool.generation.cache
import
(
cache_context
,
generator_factory
,
retrieve_cache_items
,
delete_cache_items
,
)
...
...
This diff is collapsed.
Click to expand it.
python/dune/perftool/generation/cache.py
+
33
−
0
View file @
fffca594
...
...
@@ -7,9 +7,35 @@ a complex requirement structure. This includes:
from
__future__
import
absolute_import
from
pytools
import
memoize
# have one cache the module level. It is easier than handing around an instance of it.
_cache
=
{}
# Implement a context manager that allows to temporarily define tags globally.
_cache_context_stack
=
[]
class
_CacheContext
(
object
):
def
__init__
(
self
,
tags
):
self
.
tags
=
tags
def
__enter__
(
self
):
_cache_context_stack
.
append
(
self
.
tags
)
def
__exit__
(
self
,
exc_type
,
exc_value
,
traceback
):
_cache_context_stack
.
pop
()
def
cache_context
(
*
tags
):
return
_CacheContext
(
tags
)
def
_get_context_tags
():
result
=
tuple
()
for
items
in
_cache_context_stack
:
result
=
result
+
items
return
result
def
_freeze
(
data
):
"""
A function that deterministically generates an
...
...
@@ -105,6 +131,13 @@ class _RegisteredFunction(object):
):
self
.
func
=
func
self
.
cache_key_generator
=
cache_key_generator
# Append the current context item tags to the given ones
if
'
item_tags
'
in
kwargs
:
kwargs
[
'
item_tags
'
]
=
tuple
(
kwargs
[
'
item_tags
'
])
+
_get_context_tags
()
else
:
kwargs
[
'
item_tags
'
]
=
_get_context_tags
()
self
.
itemtype
=
_construct_cache_item_type
(
"
CacheItemType
"
,
**
kwargs
)
def
__call__
(
self
,
*
args
,
**
kwargs
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment