Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #780 remember callback #781

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/masonite/cache/drivers/FileDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def remember(self, key, callable):

callable(self)

return self.get(key)

def forget(self, key):
try:
os.remove(os.path.join(self._get_directory(), key))
Expand Down
2 changes: 2 additions & 0 deletions src/masonite/cache/drivers/MemcacheDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def remember(self, key, callable):

callable(self)

return self.get(key)

def forget(self, key):
return self.get_connection().delete(f"{self.get_name()}_cache_{key}")

Expand Down
2 changes: 2 additions & 0 deletions src/masonite/cache/drivers/RedisDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ def remember(self, key: str, callable):

callable(self)

return self.get(key)

def forget(self, key: str) -> None:
self.get_connection().delete(f"{self.get_cache_namespace()}{key}")
self._internal_cache.pop(key)
Expand Down
6 changes: 3 additions & 3 deletions tests/features/cache/test_file_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def test_forget(self):
self.assertEqual(self.driver.get("forget"), None)

def test_remember(self):
self.driver.remember("remember", lambda cache: (cache.put("remember", "1", 10)))
self.assertEqual(self.driver.get("remember"), "1")
data_to_remember = self.driver.remember("remember", lambda cache: (cache.put("remember", "1", 10)))
self.assertEqual(data_to_remember, "1")

def test_remember_datatypes(self):
self.driver.remember(
Expand All @@ -60,7 +60,7 @@ def test_flush(self):
self.driver.flush()
self.assertIsNone(self.driver.get("dic"))

def test_get_can_forget_expired(self):
def test_get_can_forget_expired(self):
self.driver.put("forget_expired", "1", 1)
time.sleep(1)
self.assertEqual(self.driver.get("forget_expired"), None)
Expand Down
Loading