Skip to content

Commit

Permalink
fixed example
Browse files Browse the repository at this point in the history
  • Loading branch information
zmumi committed May 4, 2024
1 parent 5cd859f commit eaf4ac8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.2.2
-----

* Fixed an example, that used deprecated `utcnow`

1.2.1
-----

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ a custom :class:`memoize.entrybuilder.CacheEntryBuilder`.
class TtlRespectingCacheEntryBuilder(CacheEntryBuilder):
def build(self, key: CacheKey, value: ValueWithTTL):
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)
ttl_ends_at = now + datetime.timedelta(seconds=value.ttl_seconds)
return CacheEntry(
created=now,
Expand Down
10 changes: 5 additions & 5 deletions examples/ttl/ttl_asyncio.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# needed if one has tornado installed (could be removed otherwise)
from memoize import memoize_configuration
memoize_configuration.force_asyncio = True

import datetime
import asyncio
import random
Expand All @@ -9,10 +13,6 @@
from memoize.entrybuilder import CacheEntryBuilder
from memoize.storage import LocalInMemoryCacheStorage

# needed if one has tornado installed (could be removed otherwise)
from memoize import memoize_configuration
memoize_configuration.force_asyncio = True


@dataclass
class ValueWithTTL:
Expand All @@ -22,7 +22,7 @@ class ValueWithTTL:

class TtlRespectingCacheEntryBuilder(CacheEntryBuilder):
def build(self, key: CacheKey, value: ValueWithTTL):
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)
ttl_ends_at = now + datetime.timedelta(seconds=value.ttl_seconds)
return CacheEntry(
created=now,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def prepare_description():

setup(
name='py-memoize',
version='1.2.1',
version='1.2.2',
author='Michal Zmuda',
author_email='[email protected]',
url='https://github.com/DreamLab/memoize',
Expand Down

0 comments on commit eaf4ac8

Please sign in to comment.