Promote horizon.utils.memoized to Oslo
This blueprint is to promote code from Horizon to Oslo for use across OpenStack projects.
http://
I have seen a number of patches where people have begun to implement
their own caches in dictionaries. This typically confuses the code and
mixes issues of correctness and performance in code.
Here's an example:
We start with:
def my_thing_
# do expensive work
return value
... but a performance problem is detected... maybe the method is
called 15 times in 10 seconds but then not again for 5 minutes and the
return value can only logically change every minute or two... so we
end up with ...
_GLOBAL_
def my_thing_
key = key_from(some_args)
if key in _GLOBAL_
return _GLOBAL_
else:
# do expensive work
return value
... which is all well and good... but now as a maintenance programmer
I need to comprehend the cache mechanism, when cached values are
invalidated, and if I need to debug the "do expensive work" part I
need to tease out some test that prevents the cache from being hit.
Plus I've introduced a new global variable. We love globals right?
I would like us to be able to say:
@memoized
def my_thing_
# do expensive work
return value
... in Nova, Cinder, or Swift ... just as they can in Horizon.
Blueprint information
- Status:
- Started
- Approver:
- Doug Hellmann
- Priority:
- Low
- Drafter:
- Shawn Hartsock
- Direction:
- Needs approval
- Assignee:
- Shawn Hartsock
- Definition:
- Approved
- Series goal:
- None
- Implementation:
- Good progress
- Milestone target:
- None
- Started by
- Shawn Hartsock
- Completed by
Related branches
Related bugs
Sprints
Whiteboard
Note:
see also
* https:/
Code at:
https:/
TODO: the memoized.py did not appear to have any matching testing associated with it. I will write some unit tests to cover basic use before removing the WIP tag on the patch.
TODO:
Based on feeback, I am attempting to break this into an alternative cache backend and a decorator.
----
How is this substantially different from https:/
Other than the backing, that is the same basic idea.