Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Am K committed Sep 21, 2024
1 parent 2d4308a commit e0dd28a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,16 @@ 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

```python
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()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='zcache',
version='v1.0.3',
version='v1.0.4',
packages=['zcache',],
license='MIT',
author="guangrei",
Expand Down
13 changes: 8 additions & 5 deletions zcache/Extras/Queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())):
Expand All @@ -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."""
Expand Down
4 changes: 2 additions & 2 deletions zcache/Extras/SmartRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e0dd28a

Please sign in to comment.