diff --git a/README.md b/README.md index 8c7e4af..a6f40b7 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ class MyRequest: req = SmartRequest(MyRequest, cache_path="/tmp/request2.cache") ``` -> from zcache 1.0.3 SmartRequest body support str & bytes and already use BytesCachePlugins to store large file/content. +> from zcache v1.0.3 SmartRequest body support bytes and already use BytesCachePlugins to store large file/content. 2. Queue @@ -104,9 +104,8 @@ req = SmartRequest(MyRequest, cache_path="/tmp/request2.cache") from zcache.Extras.Queue import Queue q = Queue() -q.put("test", id="123") # id must be a string and optional (default random uuid) -q.exists("123") -q.peek() # view top item without enqueue +id = q.put("test") +q.exists(id) q.empty() q.size() q.get() diff --git a/setup.py b/setup.py index 9d87569..60ccd20 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name='zcache', - version='v1.0.3', + version='v1.0.4', packages=['zcache',], license='MIT', author="guangrei", diff --git a/zcache/Extras/Queue.py b/zcache/Extras/Queue.py index 36b55d0..a472346 100644 --- a/zcache/Extras/Queue.py +++ b/zcache/Extras/Queue.py @@ -15,8 +15,8 @@ class Queue: - size(): Mendapatkan jumlah item dalam queue. """ - def __init__(self, path="queue.json", storage=BaseFileStorage): - self.q = Database(path=path, storage=BaseFileStorage) + def __init__(self, path="queue.json", storage=BaseFileStorage, **kwargs): + self.q = Database(path=path, storage=BaseFileStorage, **kwargs) self._stack_load() def put(self, item, id=str(uuid.uuid4())): @@ -27,9 +27,12 @@ def put(self, item, id=str(uuid.uuid4())): raise ValueError queue = self._stack_load() queue.append(id) - self.q.set(id, item) - self._stack_update(queue) - return id + a = self.q.set(id, item) + if a: + self._stack_update(queue) + return id + else: + return None def get(self): """Menghapus dan mengembalikan item pertama dari queue.""" diff --git a/zcache/Extras/SmartRequest.py b/zcache/Extras/SmartRequest.py index 5f3369b..1b47361 100644 --- a/zcache/Extras/SmartRequest.py +++ b/zcache/Extras/SmartRequest.py @@ -33,12 +33,12 @@ class SmartRequest: A class for making Smart HTTP requests with caching capabilities using PyZCache. """ - def __init__(self, url, cache_path=None, cache_time=120, offline_ttl=604800): + def __init__(self, url, cache_path=None, cache_time=120, offline_ttl=604800, **kwargs): if not isinstance(url, str): cache_name = url.url else: cache_name = url - cache = Database(path=cache_path, plugins=BytesCachePlugins) + cache = Database(path=cache_path, plugins=BytesCachePlugins, **kwargs) if cache.has(cache_name): self.response = cache.get(cache_name) self.is_loaded_from_cache = True