localmemcache_store 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,67 @@
1
+ NOT READY YET! COME BACK IN SOME DAYS.
2
+
3
+ = LocalmemcacheStore
4
+
5
+ LocalmemcacheStore[http://github.com/der-flo/localmemcache_store]
6
+ is an ActiveSupport::Cache::Store implementation to be able to use
7
+ Localmemcache[http://localmemcache.rubyforge.org/] in Rails.
8
+
9
+ Localmemcache is an ultra-fast[http://localmemcache.rubyforge.org/#performance]
10
+ and lightweight alternative to Memcached[http://www.danga.com/memcached/]
11
+ for your Rails application.
12
+ Localmemcache runs inside your Rails processes, so you don't need to
13
+ run any extra daemons. The configuration is done inside your app and
14
+ is an absolutely no-brainer.
15
+ As the name says, the cache can only be shared on your local machine
16
+ (at the time), but for your small apps scaling/networking often is
17
+ not needed. Thanks to Rails'
18
+ Cache::Store[http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html]
19
+ interface, switching later is no big deal.
20
+
21
+ Please read the requirements[http://www.danga.com/memcached/] of
22
+ Localmemcache carefully!
23
+ In production you should use a 64bit Linux variant.
24
+ Developing on Mac OS X is okay, the missing sparse file support of
25
+ HFS+ is not that problem as long as you have enough free space on your disk.
26
+
27
+ == Installation and usage
28
+ Rails::Initializer.run do |config|
29
+ [...]
30
+ config.gem 'localmemcache_store', :source => 'http://gemcutter.org'
31
+ config.cache_store = :localmemcache_store
32
+ end
33
+ Next, install the gem:
34
+ $ sudo gem install localmemcache_store --source http://gemcutter.org
35
+
36
+ *Done.* Now enjoy your superfast new cache store!
37
+
38
+ == Configuration
39
+ There are configuration defaults to start quickly, but you should consider
40
+ these two parameters:
41
+ * +:namespace+: Namespace to avoid name collisions when running multiple
42
+ Localmemcache environments on one machine. (Defaults to +:lmc_store+.)
43
+ * +:size_mb+: Specify the cache size in megabytes. Since the memory is
44
+ used only virtually, you can feel free to use great values like 4096 ;-).
45
+ Remember that this eats up your address space on 32bit systems.
46
+ (Defaults to 128).
47
+ A configuration could look like this:
48
+ config.cache_store = :localmemcache_store,
49
+ { :namespace => 'testapp', :size_mb => 256 }
50
+
51
+ == Further usage
52
+ You can find a good Rails caching intro at
53
+ RailsGuides[http://guides.rubyonrails.org/caching_with_rails.html],
54
+ they do a better job than me ;-).
55
+
56
+ The only specific enhancement with the ActiveSupport::Cache::Store
57
+ implementation is the ability to use time based expiration in just the way the
58
+ Memcached implementation does.
59
+ See ActiveSupport::Cache::LocalmemcacheStore#write.
60
+
61
+ == Feedback
62
+ Please provide feedback! Your ideas, error reports and feature requests
63
+ are very welcome. Please contact me via
64
+ Github[http://github.com/der-flo/localmemcache_store].
65
+
66
+ ---
67
+ Copyright (c) 2009 Florian Dütsch, released under the MIT license
@@ -8,17 +8,26 @@ end
8
8
  module ActiveSupport::Cache
9
9
  class LocalmemcacheStore < Store
10
10
 
11
- DataExpiresPair = Struct.new(:data, :expires_at)
12
-
11
+ DataExpiresPair = Struct.new(:data, :expires_at) #:nodoc:
12
+
13
+ # Useful options:
14
+ # * +:namespace+: Namespace to avoid name collisions, defaults to
15
+ # +:lmc_store+.
16
+ #
17
+ # This is escpecially useful if to run seperated caches on one machine.
18
+ # * +:size_mb+: Size of the cache, defaults to +128+.
13
19
  def initialize options = {}
14
- # TODO: Define default parameters
15
20
  options.reverse_merge!({
16
- :namespace => :x,
17
- :size_mb => 64
21
+ :namespace => :lmc_store,
22
+ :size_mb => 128
18
23
  })
19
- @lmc = LocalMemCache::SharedObjectStorage.new options
24
+ @size_mb = options[:size_mb]
25
+ @lmc = LocalMemCache::ExpiryCache.new options
20
26
  end
21
27
 
28
+ # Reads a value by +name+.
29
+ #
30
+ # (options are ignored at the time)
22
31
  def read(name, options = nil)
23
32
  super
24
33
  data_expires_pair = @lmc[name]
@@ -29,13 +38,16 @@ module ActiveSupport::Cache
29
38
  data_expires_pair.expires_at <= Time.now
30
39
 
31
40
  # delete entry from database
32
- @lmc.delete(name)
41
+ @lmc.hash.delete(name)
33
42
  nil
34
43
  else
35
44
  data_expires_pair.data
36
45
  end
37
46
  end
38
47
 
48
+ # Writes a +name+-+value+ pair to the cache.
49
+ # Useful options:
50
+ # * +:expires_in+: Number of seconds an entry is valid
39
51
  def write(name, value, options = {})
40
52
  super
41
53
  data = value.freeze
@@ -47,27 +59,33 @@ module ActiveSupport::Cache
47
59
  data
48
60
  end
49
61
 
62
+ # Delete a pair by key name
63
+ #
64
+ # (options are ignored at the time)
50
65
  def delete(name, options = nil)
51
66
  super
52
67
  @lmc.delete(name)
53
68
  end
54
69
 
70
+ # Delete all pair with key matching matcher
71
+ #
72
+ # (options are ignored at the time)
55
73
  def delete_matched(matcher, options = nil)
56
74
  super
57
- # TODO: Performance?
58
75
  @lmc.each_pair do |key, value|
59
- next unless key =~ matcher
60
- @lmc.delete(key)
76
+ @lmc.delete(key) if key =~ matcher
61
77
  end
62
78
  end
63
79
 
64
- def exist?(name,options = nil)
80
+ # Checks key for existance
81
+ #
82
+ # (options are ignored at the time)
83
+ def exist?(name, options = nil)
65
84
  super
66
- # TODO: Performance?
67
- # Read the value and check for nil?
68
- @lmc.keys.include?(name)
85
+ !@lmc[name].nil?
69
86
  end
70
87
 
88
+ # Clears the entire cache.
71
89
  def clear
72
90
  @lmc.clear
73
91
  end
@@ -1,6 +1,5 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
1
2
  require File.dirname(__FILE__) + '/cache_store_behavior.rb'
2
- require 'test_helper'
3
- require 'active_support/cache/localmemcache_store'
4
3
 
5
4
  # Most tests borrowed from the Rails tests
6
5
  # http://github.com/rails/rails/blob/master/activesupport/test/caching_test.rb
@@ -8,12 +7,12 @@ require 'active_support/cache/localmemcache_store'
8
7
  class LocalmemcacheStoreTest < ActiveSupport::TestCase
9
8
 
10
9
  def setup
11
- @cache = ActiveSupport::Cache.lookup_store(:localmemcache_store)
10
+ @cache = ActiveSupport::Cache.lookup_store(:localmemcache_store, { :namespace => 'lmc_store_test' })
12
11
  @cache.clear
13
12
  @cache.silence!
14
13
  @cache.logger = Logger.new("/dev/null")
15
14
  end
16
-
15
+
17
16
  test "write a value to the cache" do
18
17
  assert_nothing_raised do
19
18
  value = :value
@@ -21,7 +20,7 @@ class LocalmemcacheStoreTest < ActiveSupport::TestCase
21
20
  assert_equal ret, value
22
21
  end
23
22
  end
24
-
23
+
25
24
  test "read a cached value" do
26
25
  assert_nothing_raised do
27
26
  value = :value
@@ -29,7 +28,7 @@ class LocalmemcacheStoreTest < ActiveSupport::TestCase
29
28
  assert_equal value, @cache.read(:key)
30
29
  end
31
30
  end
32
-
31
+
33
32
  test "entry expires" do
34
33
  value = :value
35
34
  @cache.write :key, value, :expires_in => 1.second
@@ -37,9 +36,9 @@ class LocalmemcacheStoreTest < ActiveSupport::TestCase
37
36
  sleep 2
38
37
  assert_nil @cache.read(:key)
39
38
  end
40
-
39
+
41
40
  include CacheStoreBehavior
42
-
41
+
43
42
  def test_store_objects_should_be_immutable
44
43
  @cache.write('foo', 'bar')
45
44
  @cache.read('foo').gsub!(/.*/, 'baz')
data/test/test_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
+ require 'test/unit'
1
2
  require 'rubygems'
2
3
  require 'active_support'
3
4
  require 'active_support/test_case'
5
+ require 'lib/active_support/cache/localmemcache_store'
4
6
 
5
- require File.dirname(__FILE__) + '/../rails/init.rb'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localmemcache_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Florian D\xC3\xBCtsch (der_flo)"
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-11 00:00:00 +02:00
12
+ date: 2009-10-27 00:00:00 +01:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: localmemcache
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.4.3
24
+ version:
16
25
  description:
17
26
  email: mail@florian-duetsch.de
18
27
  executables: []
@@ -20,16 +29,13 @@ executables: []
20
29
  extensions: []
21
30
 
22
31
  extra_rdoc_files:
23
- - README
32
+ - README.rdoc
24
33
  files:
25
34
  - MIT-LICENSE
26
- - Rakefile
27
- - README
28
- - TODOs.txt
35
+ - README.rdoc
29
36
  - lib/active_support/cache/localmemcache_store.rb
30
37
  - lib/localmemcache_store.rb
31
38
  - rails/init.rb
32
- - tasks/localmemcache_store_tasks.rake
33
39
  - test/cache_store_behavior.rb
34
40
  - test/localmemcache_store_test.rb
35
41
  - test/test_helper.rb
@@ -38,8 +44,8 @@ homepage: http://github.com/der-flo/localmemcache_store
38
44
  licenses: []
39
45
 
40
46
  post_install_message:
41
- rdoc_options: []
42
-
47
+ rdoc_options:
48
+ - --charset=UTF-8
43
49
  require_paths:
44
50
  - lib
45
51
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -61,5 +67,7 @@ rubygems_version: 1.3.5
61
67
  signing_key:
62
68
  specification_version: 3
63
69
  summary: A Rails cache store implementation for localmemcache
64
- test_files: []
65
-
70
+ test_files:
71
+ - test/cache_store_behavior.rb
72
+ - test/localmemcache_store_test.rb
73
+ - test/test_helper.rb
data/README DELETED
@@ -1,16 +0,0 @@
1
- NOT READY YET! COME BACK IN SOME DAYS.
2
-
3
-
4
- LocalmemcacheStore
5
- ==================
6
-
7
- Introduction goes here.
8
-
9
-
10
- Example
11
- =======
12
-
13
- Example goes here.
14
-
15
-
16
- Copyright (c) 2009 [name of plugin creator], released under the MIT license
data/Rakefile DELETED
@@ -1,59 +0,0 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
-
5
- require 'rubygems'
6
- require 'rake/gempackagetask'
7
-
8
- desc 'Default: run unit tests.'
9
- task :default => :test
10
-
11
- desc 'Test the localmemcache_store plugin.'
12
- Rake::TestTask.new(:test) do |t|
13
- t.libs << 'lib'
14
- t.libs << 'test'
15
- t.pattern = 'test/**/*_test.rb'
16
- t.verbose = true
17
- end
18
-
19
- desc 'Generate documentation for the localmemcache_store plugin.'
20
- Rake::RDocTask.new(:rdoc) do |rdoc|
21
- rdoc.rdoc_dir = 'rdoc'
22
- rdoc.title = 'LocalmemcacheStore'
23
- rdoc.options << '--line-numbers' << '--inline-source'
24
- rdoc.rdoc_files.include('README')
25
- rdoc.rdoc_files.include('lib/**/*.rb')
26
- end
27
-
28
- ################################################################################
29
- # GEM stuff
30
-
31
- PKG_FILES = FileList[
32
- '[a-zA-Z]*',
33
- # 'generators/**/*',
34
- 'lib/**/*',
35
- 'rails/**/*',
36
- 'tasks/**/*',
37
- 'test/**/*'
38
- ]
39
-
40
- # TODO: Dependency
41
-
42
- spec = Gem::Specification.new do |s|
43
- s.name = "localmemcache_store"
44
- s.version = "0.0.2"
45
- s.author = "Florian Dütsch (der_flo)"
46
- s.email = "mail@florian-duetsch.de"
47
- s.homepage = "http://github.com/der-flo/localmemcache_store"
48
- s.platform = Gem::Platform::RUBY
49
- s.summary = "A Rails cache store implementation for localmemcache"
50
- s.files = PKG_FILES.to_a
51
- s.require_path = "lib"
52
- s.has_rdoc = false
53
- s.extra_rdoc_files = ["README"]
54
- end
55
-
56
- desc 'Turn this plugin into a gem.'
57
- Rake::GemPackageTask.new(spec) do |pkg|
58
- pkg.gem_spec = spec
59
- end
data/TODOs.txt DELETED
@@ -1,15 +0,0 @@
1
- Plugin
2
- * Better / more complete tests
3
- * Stuff from http://guides.rubyonrails.org/plugins.html
4
- * Good default parameters for localmemcache configuration
5
- * Documentation! (README, Homepage, ...)
6
- * Some Rake tasks?
7
- * Statistics
8
- ** Controller generator?
9
- ** Via Rails Engines?
10
-
11
- Adjustment proposals for localmemcache
12
- * Do expiry handling inside the cache
13
- * Drop old entries instead of raising OutOfMemoryError
14
- * Add statistics: How much used / free memory?
15
- * delete_matched: Delete entries by regex
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :localmemcache_store do
3
- # # Task goes here
4
- # end