canonicurl 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,6 @@ module Canonicurl
6
6
  class Cache
7
7
  CANONICAL = 'C'
8
8
  ERROR = 'E'
9
- LOCKED = 'L'
10
9
  RESOLVING = 'R'
11
10
 
12
11
  TTL = 60 * 60 * 24 * 90 # 90 days ~ 3 months
@@ -38,21 +37,19 @@ module Canonicurl
38
37
 
39
38
  def fetch(url, resolver)
40
39
  k = key(url)
41
- @db.setnx(k, LOCKED) # lock it if key doesn't exist
40
+
41
+ # New URL resolve it
42
+ if @db.setnx(k, RESOLVING) # lock it if key doesn't exist
43
+ return resolve(url, k, resolver)
44
+ end
42
45
 
43
46
  result = @db.get(k)
44
47
  if !result.nil? && result.size > 1
45
- return result
48
+ return result # Found old noncanonical URL mapping
46
49
  end
47
50
 
48
- case result
49
- when CANONICAL
50
- url
51
- when LOCKED
52
- resolve(url, k, resolver)
53
- else
54
- result
55
- end
51
+ # CANONICAL, ERROR or RESOLVING
52
+ result == CANONICAL ? url : result
56
53
  end
57
54
 
58
55
 
@@ -1,3 +1,3 @@
1
1
  module Canonicurl
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canonicurl
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Dai
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-07 00:00:00 Z
18
+ date: 2011-04-08 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: redis