yaccl 0.0.22 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGI3MTMzNDY0MTNlOWI1YTllM2EwODVkYTEwNWZhZDMzYjQ3OTliYw==
4
+ NTY1ZDVhM2UwMmFlMGQ2MWU2NTFkZmE4YTQ2YzVmNmZiZjE2Y2MyNg==
5
5
  data.tar.gz: !binary |-
6
- MTc2ODUyMjM2NjJlNWU4ZWY5MDQ4ZWQwNTJlMjA3YWNmNmE4MjljZg==
6
+ Zjc3NjgyNWZjZjVjZDIxMjI2ZjkxZjE4M2Q1M2QzN2E4ZDEwZmM0NA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YjBiNjQzNGUzZWNmZjdhNzU0NTFhZjIxZGI2MjQ0NDU4NzFjNzk2YTYzNWZk
10
- ZTg4NTk3OWVmZjc5ZTE2Nzk4OTQ1MWNkYzA5Yzk2YTkyMjZkOGI0NWFkZTE3
11
- MTk5ZDFkODkwNDM2ZTFkODA5YjhiOThiYjllNGU2YWQ0NDNmNzQ=
9
+ NTJhOWNiMDgzZWVkYzgwMjE5YTMzM2Y1YTE1NDg4NGI2ODVlMGVhYWYwMWFi
10
+ NTNlNmZiZDM4ZmI5ODRlNWY1MTA5NGIyNmNhZDJiMWNiZTQ4MmY5ODFmOGZl
11
+ NjUzNmE2Y2UxNjFjYTZlYzI3YjYwY2NhMTE1OTBiNGMwMjM1ZjM=
12
12
  data.tar.gz: !binary |-
13
- YjkwOGU1NjgyZTI5OTFlYzU5ZGFmOWE1MjcxMWYwZGMzOTc2ZWIyNzY5YzRm
14
- ZWM0NGM4NjliYTQ1ZWNmOTU1ZTMwNmFhNzk4OWE3OTAzYTMwMGNlMjhhYjFi
15
- NWM1NmY2Nzg3MWU4ODUyMmYzYjA2OTFhYTM2NGJhZDllMGZmNjM=
13
+ MDkzNGZjNDU5YTllODUyMTk0ZWIzYjQzNWNhMjc4MmQ4MTQ5MmFiNTBjZGRk
14
+ ZDhjYmM3YWU1N2QxMjcxNzQwMjU2YWI5Y2U4NzZmNmM3NDMxY2Y0M2UzNGFi
15
+ ZGEzZDc4ZTFhN2IwODQxYWNiZjJhOGViMzlmYWRmZmZiMjA5MWY=
@@ -1,7 +1,7 @@
1
1
  require 'httparty'
2
2
  require 'net/http/post/multipart'
3
3
  require 'multi_json'
4
- require 'volatile_hash'
4
+ require_relative 'simple_cache'
5
5
 
6
6
  module YACCL
7
7
  module Services
@@ -9,14 +9,13 @@ module YACCL
9
9
 
10
10
  module Internal
11
11
  class BrowserBindingService
12
+
13
+ @@url_cache = SimpleCache::MemoryCache.new
14
+
12
15
  def initialize(service_url, basic_auth_username=nil, basic_auth_password=nil, succinct_properties=true)
13
16
  @service_url = service_url
14
17
  @basement = Basement.new(basic_auth_username, basic_auth_password)
15
-
16
18
  @succinct_properties = succinct_properties
17
-
18
- @repository_urls = VolatileHash.new(strategy: 'lru')
19
- @root_folder_urls = VolatileHash.new(strategy: 'lru')
20
19
  end
21
20
 
22
21
  def perform_request(required_params={}, optional_params={})
@@ -45,9 +44,9 @@ module YACCL
45
44
  end
46
45
  unless (200...300).include?(response.code.to_i)
47
46
  if result.is_a?(Hash) && result.has_key?(:exception)
48
- raise CMISRequestError, "#{result[:exception]} -- #{result[:message]}"
47
+ raise CMISRequestError, "#{response.code} -- #{result[:exception]} -- #{result[:message]}"
49
48
  else
50
- raise CMISRequestError, "#{result}"
49
+ raise CMISRequestError, "#{response.code} -- #{result}"
51
50
  end
52
51
  end
53
52
 
@@ -60,22 +59,19 @@ module YACCL
60
59
  if repository_id.nil?
61
60
  @service_url
62
61
  else
63
- if object_id.nil?
64
- if @repository_urls[repository_id].nil?
65
- base = @basement.get(@service_url)
66
- raise "No repository found with ID: #{repository_id}." unless base[repository_id]
67
- repository_url = base[repository_id]['repositoryUrl']
68
- @repository_urls[repository_id] = repository_url
69
- end
70
- return @repository_urls[repository_id]
71
- else
72
- if @root_folder_urls[repository_id].nil?
73
- root_folder_url = @basement.get(@service_url)[repository_id]['rootFolderUrl']
74
- @root_folder_urls[repository_id] = root_folder_url
75
- end
76
- return @root_folder_urls[repository_id]
77
- end
62
+ repository_urls(repository_id)[object_id ? :root_folder_url : :repository_url]
63
+ end
64
+ end
65
+
66
+ def repository_urls(repository_id)
67
+ if @@url_cache[repository_id].nil?
68
+ repository_infos = @basement.get(@service_url)
69
+ raise "No repository found with ID #{repository_id}." unless repository_infos.has_key?(repository_id)
70
+ repository_info = repository_infos[repository_id]
71
+ @@url_cache[repository_id] = { repository_url: repository_info['repositoryUrl'],
72
+ root_folder_url: repository_info['rootFolderUrl'] }
78
73
  end
74
+ @@url_cache[repository_id]
79
75
  end
80
76
 
81
77
  def check(hash)
@@ -0,0 +1,97 @@
1
+ =begin
2
+ Code taken mostly from ActiveRecord::Cache
3
+ Copyright (c) 2005-2011 David Heinemeier Hansson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ =end
25
+ require 'digest/md5'
26
+ module SimpleCache
27
+ #TODO: add a super-class and implement FileSystemCache
28
+ class MemoryCache
29
+
30
+ attr_reader :cache_size
31
+
32
+ def initialize(options = {})
33
+ @cache = {}
34
+ @cache_size = 0
35
+ @key_access = {}
36
+ @max_size = options[:max_size] || 32 * 1024 #32 megabytes
37
+ @timeout = options[:timeout] || 60*30 #30 minutes
38
+ end
39
+
40
+ def encode(key)
41
+ Digest::MD5.hexdigest key
42
+ end
43
+
44
+ def delete(key)
45
+ entry = @cache.delete key
46
+ @key_access.delete key
47
+ @cache_size -= entry.size
48
+ end
49
+
50
+ def [](key)
51
+ key = encode(key)
52
+ entry = @cache[key]
53
+ if entry
54
+ @key_access[key] = Time.now.to_f
55
+ else
56
+ @key_access.delete key
57
+ end
58
+ entry
59
+ end
60
+
61
+ def []=(key, value)
62
+ key = encode(key)
63
+ old_entry = @cache[key]
64
+ @cache_size -= old_entry.size if old_entry
65
+ @key_access[key] = Time.now.to_f
66
+ @cache[key] = value
67
+ @cache_size += value.size
68
+ prune if @cache_size > @max_size
69
+ end
70
+
71
+ def has_key?(key)
72
+ !!@cache[encode(key)]
73
+ end
74
+
75
+ def prune
76
+ # first, the obvious cleanup
77
+ @cache.keys.each do |key|
78
+ delete(key) if stale? key
79
+ end
80
+
81
+ # now, try to leave it a 3/4 of it's capacity
82
+ target_size = 0.75 * @max_size
83
+
84
+ # delete the older entries
85
+ sorted_keys = @key_access.keys.sort{|a,b| @key_access[a].to_f <=> @key_access[b].to_f}
86
+ sorted_keys.each do |key|
87
+ return if @cache_size <= target_size
88
+ delete key
89
+ end
90
+ end
91
+
92
+ def stale?(key)
93
+ (Time.now.to_f - @key_access[key]) > @timeout.to_f
94
+ end
95
+
96
+ end
97
+ end
@@ -1,3 +1,3 @@
1
1
  module YACCL
2
- VERSION = '0.0.22'
2
+ VERSION = '0.0.23'
3
3
  end
@@ -15,7 +15,6 @@ Gem::Specification.new do |s|
15
15
  s.add_dependency 'httparty', '~> 0.10'
16
16
  s.add_dependency 'multipart-post', '~> 1.1'
17
17
  s.add_dependency 'multi_json', '~> 1.5'
18
- s.add_dependency 'volatile_hash', '~> 0.0.2'
19
18
 
20
19
  s.files = `git ls-files`.split("\n")
21
20
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaccl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenneth Geerts
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-02 00:00:00.000000000 Z
12
+ date: 2013-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -53,20 +53,6 @@ dependencies:
53
53
  - - ~>
54
54
  - !ruby/object:Gem::Version
55
55
  version: '1.5'
56
- - !ruby/object:Gem::Dependency
57
- name: volatile_hash
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ~>
61
- - !ruby/object:Gem::Version
62
- version: 0.0.2
63
- type: :runtime
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: 0.0.2
70
56
  description: A Ruby CMIS browser binding client library implementation.
71
57
  email:
72
58
  - gem@up-nxt.com
@@ -96,6 +82,7 @@ files:
96
82
  - lib/yaccl/services/acl_services.rb
97
83
  - lib/yaccl/services/discovery_services.rb
98
84
  - lib/yaccl/services/internal/browser_binding_service.rb
85
+ - lib/yaccl/services/internal/simple_cache.rb
99
86
  - lib/yaccl/services/multi_filing_services.rb
100
87
  - lib/yaccl/services/navigation_services.rb
101
88
  - lib/yaccl/services/object_services.rb