pebblebed 0.0.33 → 0.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,9 @@
2
2
  module Pebblebed
3
3
  module Security
4
4
  class Client
5
- IDENTITY_MEMBERSHIPS_TTL = 10*60
5
+ # TTL is reset for every cache hit, so actual TTL might be much longer
6
+ # as long as the user keeps hitting that cache.
7
+ IDENTITY_MEMBERSHIPS_TTL = 10
6
8
 
7
9
  def initialize(connector)
8
10
  @connector = connector
@@ -22,9 +24,11 @@ module Pebblebed
22
24
  private
23
25
 
24
26
  def fetch_membership_data_for(identity)
25
- result = Pebblebed.memcached.fetch("identity_membership_data:#{identity}", IDENTITY_MEMBERSHIPS_TTL) do
27
+ cache_key = "identity_membership_data:#{identity}"
28
+ result = Pebblebed.memcached.fetch(cache_key, IDENTITY_MEMBERSHIPS_TTL) do
26
29
  @connector.checkpoint.get("/identities/#{identity}/memberships").to_json
27
30
  end
31
+ Pebblebed.memcached.touch(cache_key, IDENTITY_MEMBERSHIPS_TTL)
28
32
  JSON.parse(result)
29
33
  end
30
34
 
@@ -4,6 +4,10 @@ require 'pebblebed'
4
4
  module Sinatra
5
5
  module Pebblebed
6
6
  module Helpers
7
+ # Cache identity for this amount of seconds. TTL will be reset each cache hit,
8
+ # so real TTL might be much longer than this.
9
+ IDENTITY_CACHE_TTL = 10
10
+
7
11
  # Render the markup for a part. A partspec takes the form
8
12
  # "<kit>.<partname>", e.g. "base.post"
9
13
  def part(partspec, params = {})
@@ -39,10 +43,13 @@ module Sinatra
39
43
  if cache_current_identity?
40
44
  cache_key = "identity-for-session-#{current_session}"
41
45
  @identity = ::Pebblebed.memcached.get(cache_key)
42
- return @identity if @identity
46
+ if @identity
47
+ ::Pebblebed.memcached.touch(cache_key, IDENTITY_CACHE_TTL)
48
+ return @identity
49
+ end
43
50
  @identity = pebbles.checkpoint.get("/identities/me")[:identity]
44
51
  # Cache identity only if there is a current user
45
- ::Pebblebed.memcached.set(cache_key, @identity, 60) if @identity.id?
52
+ ::Pebblebed.memcached.set(cache_key, @identity, IDENTITY_CACHE_TTL) if @identity.id?
46
53
  else
47
54
  @identity = pebbles.checkpoint.get("/identities/me")[:identity]
48
55
  end
@@ -1,3 +1,3 @@
1
1
  module Pebblebed
2
- VERSION = "0.0.33"
2
+ VERSION = "0.0.34"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pebblebed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33
4
+ version: 0.0.34
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-11-23 00:00:00.000000000 Z
13
+ date: 2012-11-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -328,7 +328,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
328
328
  version: '0'
329
329
  segments:
330
330
  - 0
331
- hash: -222285177429713152
331
+ hash: -2833651708453981054
332
332
  required_rubygems_version: !ruby/object:Gem::Requirement
333
333
  none: false
334
334
  requirements:
@@ -337,7 +337,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
337
337
  version: '0'
338
338
  segments:
339
339
  - 0
340
- hash: -222285177429713152
340
+ hash: -2833651708453981054
341
341
  requirements: []
342
342
  rubyforge_project: pebblebed
343
343
  rubygems_version: 1.8.24