def encode(self, dataset, params: EncoderParams): cache_key = CacheHandler.generate_cache_key( self._prepare_caching_params(dataset, params)) encoded_dataset = CacheHandler.memo( cache_key, lambda: self._encode_new_dataset(dataset, params)) return encoded_dataset
def run(input_params: DataSplitterParams = None): cache_key = CacheHandler.generate_cache_key( DataSplitter._prepare_caching_params(input_params)) fn = getattr( DataSplitter, "{}_split".format(input_params.split_strategy.name.lower())) datasets = CacheHandler.memo(cache_key, lambda: fn(input_params)) return datasets
def test_memo(self): fn = lambda: "abc" cache_key = "a123" obj = CacheHandler.memo(cache_key, fn) self.assertEqual("abc", obj) os.remove( CacheHandler._build_filename(cache_key, CacheObjectType.OTHER))
def test_memo_with_object_type(self): fn = lambda: "abc" cache_key = "a123" obj = CacheHandler.memo(cache_key, fn, CacheObjectType.ENCODING) self.assertEqual("abc", obj) self.assertTrue( os.path.isfile(EnvironmentSettings.get_cache_path() / f"encoding/{cache_key}.pickle")) os.remove( CacheHandler._build_filename(cache_key, CacheObjectType.ENCODING))