Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/vault/cache.py
# Copyright (C) 2016 The Software Heritage developers | # Copyright (C) 2016 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import os | import os | ||||
from swh.core import hashutil | from swh.core import hashutil | ||||
from swh.objstorage import get_objstorage | from swh.objstorage import get_objstorage | ||||
from swh.objstorage.objstorage_pathslicing import DIR_MODE | from swh.objstorage.objstorage_pathslicing import DIR_MODE | ||||
BUNDLE_TYPES = { | BUNDLE_TYPES = { | ||||
'directory': 'd', | 'directory': 'd', | ||||
'revision': 'r', | |||||
'snapshot': 's', | |||||
} | } | ||||
class VaultCache(): | class VaultCache(): | ||||
"""The vault cache is an object storage that stores bundles | """The vault cache is an object storage that stores bundles | ||||
The current implementation uses a PathSlicingObjStorage to store | The current implementation uses a PathSlicingObjStorage to store | ||||
the bundles. The id of a content if prefixed to specify its type | the bundles. The id of a content if prefixed to specify its type | ||||
Show All 11 Lines | def __init__(self, root): | ||||
type: get_objstorage( | type: get_objstorage( | ||||
'pathslicing', {'root': os.path.join(root, subdir), | 'pathslicing', {'root': os.path.join(root, subdir), | ||||
'slicing': '0:1/0:5'} | 'slicing': '0:1/0:5'} | ||||
) | ) | ||||
for type, subdir in BUNDLE_TYPES.items() | for type, subdir in BUNDLE_TYPES.items() | ||||
} | } | ||||
def __contains__(self, obj_id): | def __contains__(self, obj_id): | ||||
return obj_id in self.storage | for storage in self.storages: | ||||
if obj_id in storage: | |||||
return True | |||||
return False | |||||
def add(self, obj_type, obj_id, content): | def add(self, obj_type, obj_id, content): | ||||
storage = self._get_storage(obj_type) | storage = self._get_storage(obj_type) | ||||
return storage.add(content, obj_id) | return storage.add(content, obj_id) | ||||
def get(self, obj_type, obj_id): | def get(self, obj_type, obj_id): | ||||
storage = self._get_storage(obj_type) | storage = self._get_storage(obj_type) | ||||
return storage.get(hashutil.hex_to_hash(obj_id)) | return storage.get(hashutil.hex_to_hash(obj_id)) | ||||
Show All 15 Lines |