-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#20] * Added configurable postprocessing, that allows to modify valu…
…e retrieved from the cache (#30) * [#20] * Added configurable postprocessing, that allows to modify value retrieved from the cache * Added built-in implementation, that applies deep-copy * Fix MANIFEST.in * [#20] * updated API docs --------- Co-authored-by: Michał Żmuda <[email protected]>
- Loading branch information
Showing
10 changed files
with
215 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
include requirements.txt | ||
include README.rst | ||
include CHANGELOG.md | ||
include CHANGELOG.rst |
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
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,30 @@ | ||
import copy | ||
from abc import ABCMeta, abstractmethod | ||
from typing import Any | ||
|
||
ValueType = Any | ||
|
||
|
||
class Postprocessing(metaclass=ABCMeta): | ||
@abstractmethod | ||
def apply(self, original: ValueType) -> ValueType: | ||
"""Transforms value just before returning from the cache.""" | ||
raise NotImplementedError() | ||
|
||
|
||
class NoPostprocessing(Postprocessing): | ||
def apply(self, original: ValueType) -> ValueType: | ||
"""Applies no postprocessing (returns original value).""" | ||
return original | ||
|
||
|
||
class DeepcopyPostprocessing(Postprocessing): | ||
def apply(self, original: ValueType) -> ValueType: | ||
""" | ||
Performs deep copy of the value. Useful when you want to prevent modifying the value cached in memory | ||
(so callers could modify their copies safely). | ||
Have in mind that this operation may be expensive, | ||
and may not be suitable for all types of values (see docs on copy.deepcopy). | ||
""" | ||
return copy.deepcopy(original) |
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.