Skip to content

Commit

Permalink
Typo Gready -> Greedy (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
janbjorge committed Feb 22, 2024
1 parent da57488 commit 45301f7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ APP = FastAPI(lifespan=app_setup_teardown)

# Decorate the cached_query function with cache invalidation logic.
@decorators.cache(
strategy=strategies.Greedy( # Note: Assuming 'Gready' is a typo, corrected to 'Greedy'.
strategy=strategies.Greedy(
listener=listener,
# Invalidate the cache only for 'update' operations on the database.
predicate=lambda x: x.operation == "update",
Expand Down
2 changes: 1 addition & 1 deletion src/pgcachewatch/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def connection_healthy(self) -> bool:
raise NotImplementedError


class Gready(Strategy):
class Greedy(Strategy):
"""
A strategy that clears events based on a predicate until a deadline is reached.
"""
Expand Down
28 changes: 14 additions & 14 deletions tests/test_decoraters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@


@pytest.mark.parametrize("N", (1, 2, 4, 16, 64))
async def test_gready_cache_decorator(N: int, pgconn: asyncpg.Connection) -> None:
async def test_greedy_cache_decorator(N: int, pgconn: asyncpg.Connection) -> None:
statistics = collections.Counter[str]()
listener = listeners.PGEventQueue()
await listener.connect(pgconn, models.PGChannel("test_cache_decorator"))

@decorators.cache(
strategy=strategies.Gready(listener=listener),
strategy=strategies.Greedy(listener=listener),
statistics_callback=lambda x: statistics.update([x]),
)
async def now() -> datetime.datetime:
Expand All @@ -29,18 +29,18 @@ async def now() -> datetime.datetime:


@pytest.mark.parametrize("N", (1, 2, 4, 16, 64))
async def test_gready_cache_decorator_connection_closed(
async def test_greedy_cache_decorator_connection_closed(
N: int,
pgconn: asyncpg.Connection,
) -> None:
listener = listeners.PGEventQueue()
await listener.connect(
pgconn,
models.PGChannel("test_gready_cache_decorator_connection_closed"),
models.PGChannel("test_greedy_cache_decorator_connection_closed"),
)
await pgconn.close()

@decorators.cache(strategy=strategies.Gready(listener=listener))
@decorators.cache(strategy=strategies.Greedy(listener=listener))
async def now() -> datetime.datetime:
return datetime.datetime.now()

Expand All @@ -49,17 +49,17 @@ async def now() -> datetime.datetime:


@pytest.mark.parametrize("N", (1, 2, 4, 16, 64))
async def test_gready_cache_decorator_exceptions(
async def test_greedy_cache_decorator_exceptions(
N: int,
pgconn: asyncpg.Connection,
) -> None:
listener = listeners.PGEventQueue()
await listener.connect(
pgconn,
models.PGChannel("test_gready_cache_decorator_exceptions"),
models.PGChannel("test_greedy_cache_decorator_exceptions"),
)

@decorators.cache(strategy=strategies.Gready(listener=listener))
@decorators.cache(strategy=strategies.Greedy(listener=listener))
async def raise_runtime_error() -> NoReturn:
raise RuntimeError

Expand All @@ -76,19 +76,19 @@ async def raise_runtime_error() -> NoReturn:


@pytest.mark.parametrize("N", (1, 2, 4, 16, 64))
async def test_gready_cache_identity(
async def test_greedy_cache_identity(
N: int,
pgconn: asyncpg.Connection,
) -> None:
statistics = collections.Counter[str]()
listener = listeners.PGEventQueue()
await listener.connect(
pgconn,
models.PGChannel("test_gready_cache_decorator_exceptions"),
models.PGChannel("test_greedy_cache_decorator_exceptions"),
)

@decorators.cache(
strategy=strategies.Gready(listener=listener),
strategy=strategies.Greedy(listener=listener),
statistics_callback=lambda x: statistics.update([x]),
)
async def identity(x: int) -> int:
Expand All @@ -102,19 +102,19 @@ async def identity(x: int) -> int:


@pytest.mark.parametrize("N", (1, 2, 4, 16, 64))
async def test_gready_cache_sleepy(
async def test_greedy_cache_sleepy(
N: int,
pgconn: asyncpg.Connection,
) -> None:
statistics = collections.Counter[str]()
listener = listeners.PGEventQueue()
await listener.connect(
pgconn,
models.PGChannel("test_gready_cache_decorator_exceptions"),
models.PGChannel("test_greedy_cache_decorator_exceptions"),
)

@decorators.cache(
strategy=strategies.Gready(listener=listener),
strategy=strategies.Greedy(listener=listener),
statistics_callback=lambda x: statistics.update([x]),
)
async def now() -> datetime.datetime:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def fastapitestapp(
listener = listeners.PGEventQueue()
await listener.connect(pgconn, channel)

@decorators.cache(strategy=strategies.Gready(listener=listener))
@decorators.cache(strategy=strategies.Greedy(listener=listener))
async def slow_db_read() -> dict:
await asyncio.sleep(0.1) # sim. a slow db-query.
return {"now": datetime.datetime.now().isoformat()}
Expand Down
8 changes: 4 additions & 4 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def test_2_caching(
cnt = 0

@decorators.cache(
strategy=strategies.Gready(listener=listener),
strategy=strategies.Greedy(listener=listener),
statistics_callback=lambda x: statistics.update([x]),
)
async def fetch_sysconf() -> list:
Expand All @@ -69,7 +69,7 @@ async def test_3_cache_invalidation_update(
)

@decorators.cache(
strategy=strategies.Gready(listener=listener),
strategy=strategies.Greedy(listener=listener),
statistics_callback=lambda x: statistics.update([x]),
)
async def fetch_sysconf() -> list:
Expand Down Expand Up @@ -103,7 +103,7 @@ async def test_3_cache_invalidation_insert(
)

@decorators.cache(
strategy=strategies.Gready(listener=listener),
strategy=strategies.Greedy(listener=listener),
statistics_callback=lambda x: statistics.update([x]),
)
async def fetch_sysconf() -> list:
Expand Down Expand Up @@ -138,7 +138,7 @@ async def test_3_cache_invalidation_delete(
)

@decorators.cache(
strategy=strategies.Gready(listener=listener),
strategy=strategies.Greedy(listener=listener),
statistics_callback=lambda x: statistics.update([x]),
)
async def fetch_sysconf() -> list:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@


@pytest.mark.parametrize("N", (4, 16, 64))
async def test_gready_strategy(N: int, pgconn: asyncpg.Connection) -> None:
channel = models.PGChannel("test_gready_strategy")
async def test_greedy_strategy(N: int, pgconn: asyncpg.Connection) -> None:
channel = models.PGChannel("test_greedy_strategy")

listener = listeners.PGEventQueue()
await listener.connect(pgconn, channel)

strategy = strategies.Gready(
strategy = strategies.Greedy(
listener=listener,
predicate=lambda e: e.operation == "insert",
)
Expand Down

0 comments on commit 45301f7

Please sign in to comment.