Skip to content
New issue

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

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

Already on GitHub? # to your account

Add NoOp implementations for the rest of the caches #513

Merged
merged 1 commit into from
Jun 17, 2023
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
38 changes: 38 additions & 0 deletions lib/nostrum/cache/channel_cache/noop.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
defmodule Nostrum.Cache.ChannelCache.NoOp do
@moduledoc """
A NoOp implementation for the ChannelCache

This cache does nothing, enable it if you dont need to cache channels
"""

@behaviour Nostrum.Cache.ChannelCache

alias Nostrum.Cache.ChannelCache
alias Nostrum.Struct.Channel
use Supervisor

@doc "Start the supervisor."
def start_link(init_arg) do
Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
end

@impl Supervisor
def init(_init_arg) do
Supervisor.init([], strategy: :one_for_one)
end

@impl ChannelCache
def create(channel), do: convert(channel)

@impl ChannelCache
def update(channel), do: {nil, convert(channel)}

@impl ChannelCache
def delete(_id), do: :noop

@impl ChannelCache
def query_handle, do: :qlc.string_to_handle('[].')

defp convert(%{__struct__: _} = struct), do: struct
defp convert(map), do: Channel.to_struct(map)
end
30 changes: 30 additions & 0 deletions lib/nostrum/cache/channel_guild_mapping/noop.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
defmodule Nostrum.Cache.ChannelGuildMapping.NoOp do
@moduledoc """
NoOp implementation for the Channel Guild map
"""

alias Nostrum.Cache.ChannelGuildMapping

@behaviour ChannelGuildMapping

use Supervisor

@doc "Start the supervisor."
def start_link(init_arg) do
Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
end

@impl Supervisor
def init(_init_arg) do
Supervisor.init([], strategy: :one_for_one)
end

@impl ChannelGuildMapping
def create(_channel_id, _guild_id), do: true

@impl ChannelGuildMapping
def get(_channel_id), do: nil

@impl ChannelGuildMapping
def delete(_channel_id), do: true
end
38 changes: 38 additions & 0 deletions lib/nostrum/cache/member_cache/noop.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
defmodule Nostrum.Cache.MemberCache.NoOp do
@moduledoc """
A NoOp implementation for the MemberCache

This cache does nothing, enable it if you dont need to cache members
"""
@behaviour Nostrum.Cache.MemberCache

alias Nostrum.Cache.MemberCache
alias Nostrum.Struct.Guild.Member
alias Nostrum.Util
use Supervisor

@doc "Start the supervisor."
def start_link(init_arg) do
Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
end

@impl Supervisor
def init(_init_arg) do
Supervisor.init([], strategy: :one_for_one)
end

@impl MemberCache
def create(_guild_id, payload), do: Util.cast(payload, {:struct, Member})

@impl MemberCache
def update(guild_id, payload), do: {guild_id, nil, Util.cast(payload, {:struct, Member})}

@impl MemberCache
def delete(_guild_id, _user_id), do: :noop

@impl MemberCache
def bulk_create(_guild_id, _members), do: true

@impl MemberCache
def query_handle, do: :qlc.string_to_handle('[].')
end
36 changes: 36 additions & 0 deletions lib/nostrum/cache/user_cache/noop.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
defmodule Nostrum.Cache.UserCache.NoOp do
@moduledoc """
A NoOp implementation for the UserCache

This cache does nothing, enable it if you dont need to cache users
"""
@behaviour Nostrum.Cache.UserCache

alias Nostrum.Struct.User
use Supervisor

@doc "Start the supervisor."
def start_link(init_arg) do
Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
end

@impl Supervisor
def init(_init_arg) do
Supervisor.init([], strategy: :one_for_one)
end

@impl Nostrum.Cache.UserCache
def bulk_create(_users), do: :ok

@impl Nostrum.Cache.UserCache
def create(payload), do: User.to_struct(payload)

@impl Nostrum.Cache.UserCache
def update(info), do: {nil, User.to_struct(info)}

@impl Nostrum.Cache.UserCache
def delete(_id), do: :noop

@impl Nostrum.Cache.UserCache
def query_handle, do: :qlc.string_to_handle('[].')
end