-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7388720
commit dd40cc0
Showing
17 changed files
with
88 additions
and
41 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
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
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
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
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
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
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
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
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
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
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
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,18 @@ | ||
class TouchpointCache | ||
|
||
TOUCHPOINT_NAMESPACE = "namespace:touchpoint-" | ||
|
||
# Cache Store fetch will return the cached item | ||
# or run the block if the cached item does not exist | ||
def self.fetch(id) | ||
Rails.cache.fetch(TOUCHPOINT_NAMESPACE + id.to_s, expires_in: 1.day) do | ||
#Pull in all objects required to build a touchpoint | ||
Touchpoint.includes({form: [:questions, form_sections: [questions: [:question_options]]]}, service: [:organization]).find(id) | ||
end | ||
end | ||
|
||
def self.invalidate(id) | ||
Rails.cache.delete(TOUCHPOINT_NAMESPACE + id.to_s) | ||
end | ||
|
||
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
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
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
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
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,27 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe TouchpointCache, type: :model do | ||
|
||
let!(:touchpoint) { FactoryBot.create(:touchpoint, :with_form) } | ||
|
||
describe "validate cache fetch" do | ||
context "Store and Fetch Touchpoint" do | ||
it "caches a touchpoint" do | ||
@tpc = TouchpointCache.fetch(touchpoint.id) | ||
expect(touchpoint.id).to eq(@tpc.id) | ||
end | ||
end | ||
|
||
context "Invalidate Cache" do | ||
before do | ||
@tpc = TouchpointCache.fetch(touchpoint.id) | ||
expect(touchpoint.id).to eq(@tpc.id) | ||
TouchpointCache.invalidate(touchpoint.id) | ||
end | ||
|
||
it "removes a touchpoint from cache" do | ||
expect(Rails.cache.read("namespace:touchpoint-" + touchpoint.id.to_s)).to eq(nil) | ||
end | ||
end | ||
end | ||
end |