-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #513 from Leastrio/noop
Add NoOp implementations for the rest of the caches
- Loading branch information
Showing
4 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |