Skip to content
Snippets Groups Projects
Commit be3dffbd authored by Fabian Schuh's avatar Fabian Schuh
Browse files

[asset] caching

parent 8f8b0cde
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,9 @@ from .exceptions import AssetDoesNotExistsException ...@@ -3,6 +3,9 @@ from .exceptions import AssetDoesNotExistsException
class Asset(dict): class Asset(dict):
assets_cache = dict()
def __init__( def __init__(
self, self,
asset, asset,
...@@ -21,7 +24,10 @@ class Asset(dict): ...@@ -21,7 +24,10 @@ class Asset(dict):
super(Asset, self).__init__(asset) super(Asset, self).__init__(asset)
self.cached = True self.cached = True
if not lazy and not self.cached: if self.asset in Asset.assets_cache:
super(Asset, self).__init__(Asset.assets_cache[self.asset])
self.cached = True
elif not lazy and not self.cached:
self.refresh() self.refresh()
def refresh(self): def refresh(self):
...@@ -33,6 +39,9 @@ class Asset(dict): ...@@ -33,6 +39,9 @@ class Asset(dict):
self["bitasset_data"] = self.bitshares.rpc.get_object(asset["bitasset_data_id"]) self["bitasset_data"] = self.bitshares.rpc.get_object(asset["bitasset_data_id"])
self.cached = True self.cached = True
# store in cache
Asset.assets_cache[asset["symbol"]] = asset
@property @property
def is_bitasset(self): def is_bitasset(self):
return ("bitasset_data_id" in self) return ("bitasset_data_id" in self)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment