canonicurl 0.0.6 → 0.0.7
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.
- data/lib/canonicurl/cache.rb +8 -11
- data/lib/canonicurl/version.rb +1 -1
- metadata +4 -4
data/lib/canonicurl/cache.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
49
|
-
|
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
|
|
data/lib/canonicurl/version.rb
CHANGED
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:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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-
|
18
|
+
date: 2011-04-08 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: redis
|