pogocache-ruby 0.1.1 → 0.2.1
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.
- checksums.yaml +4 -4
- data/README.md +32 -82
- data/benchmark.rb +45 -0
- data/lib/pogocache-ruby/cache.rb +50 -17
- data/lib/pogocache-ruby/version.rb +1 -1
- metadata +2 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2f4f0e5c79ce77f45196a18d56025ec9e0121d813c27522e5d6f01ff8141f1e1
         | 
| 4 | 
            +
              data.tar.gz: 5104e3f9f4a9fb635a34b8bfce6d62c1734848e4d30c2149d11270bc784b053f
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 632148b9538a2e5892b2071e1e920bcdcafe2f58f4efc42fbc10ce478bf676713c0aadd26c91e8176a5b471252280bb5e4edbbaf600d7d1923850fa0695bdd35
         | 
| 7 | 
            +
              data.tar.gz: e3fade41b2dc20d996c17d0ce0ccdfa15c2fd5a32a6d2068198c500551edccb44a5ecd90b11d4489c5fc4b9cb04effe2f4a1d4f22e4f86e639d63ef2d504e826
         | 
    
        data/README.md
    CHANGED
    
    | @@ -2,8 +2,8 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            Use [pogocache](https://github.com/tidwall/pogocache) as an in-memory store in Ruby.
         | 
| 4 4 | 
             
            This gem embeds pogocache as a C extension and provides the class `Pogocache::Cache`to interact with it.
         | 
| 5 | 
            -
            The goal is to provide a faster, more lightweight alternative to `ActiveSupport::Cache::MemoryStore | 
| 6 | 
            -
            The state of this project is  | 
| 5 | 
            +
            The goal is to provide a faster, more lightweight alternative to `ActiveSupport::Cache::MemoryStore`.
         | 
| 6 | 
            +
            The state of this project is pre release but functional. Feedback is welcome.
         | 
| 7 7 |  | 
| 8 8 | 
             
            ## Features
         | 
| 9 9 |  | 
| @@ -19,103 +19,53 @@ It does not free the lock before any operation. | |
| 19 19 |  | 
| 20 20 | 
             
            ## Usage
         | 
| 21 21 |  | 
| 22 | 
            -
            ```
         | 
| 22 | 
            +
            ```sh
         | 
| 23 23 | 
             
            bundle add pogocache-ruby
         | 
| 24 24 | 
             
            ```
         | 
| 25 | 
            +
            ```ruby
         | 
| 26 | 
            +
            require 'pogocache-ruby'
         | 
| 25 27 |  | 
| 26 | 
            -
             | 
| 28 | 
            +
            cache = Pogocache::Cache.new
         | 
| 27 29 |  | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            +
            cache.set("value1", "string 1")
         | 
| 31 | 
            +
            cache[:value2] = { hash_key: "value" }
         | 
| 30 32 |  | 
| 31 | 
            -
             | 
| 33 | 
            +
            cache.fetch(:value2)
         | 
| 34 | 
            +
            # => {hash_key: "value"}
         | 
| 35 | 
            +
            cache["value1"]
         | 
| 36 | 
            +
            # => "string 1"
         | 
| 37 | 
            +
            ```
         | 
| 32 38 |  | 
| 33 | 
            -
             | 
| 34 | 
            -
            require 'pogocache-ruby'
         | 
| 35 | 
            -
            require 'active_support'
         | 
| 36 | 
            -
            require 'active_support/cache'
         | 
| 37 | 
            -
            require 'benchmark'
         | 
| 38 | 
            -
            require 'benchmark/memory'
         | 
| 39 | 
            -
             | 
| 40 | 
            -
            memory_store = ActiveSupport::Cache::MemoryStore.new
         | 
| 41 | 
            -
            pogocache_store = Pogocache::Cache.new(usecas: true, nosixpack: true)
         | 
| 42 | 
            -
            pogocache_batch_store = Pogocache::Cache.new
         | 
| 43 | 
            -
             | 
| 44 | 
            -
            N = 100_000
         | 
| 45 | 
            -
             | 
| 46 | 
            -
            puts "Benchmarking WRITE performance (#{N} keys)..."
         | 
| 47 | 
            -
            Benchmark.bm(20) do |x|
         | 
| 48 | 
            -
              x.report("MemoryStore write:") do
         | 
| 49 | 
            -
                N.times { |i| memory_store.write("key#{i}", { number: i, value: nil}) }
         | 
| 50 | 
            -
              end
         | 
| 51 | 
            -
             | 
| 52 | 
            -
              x.report("Pogocache write:") do
         | 
| 53 | 
            -
                N.times { |i| pogocache_store.set("key#{i}", { number: i, value: nil}) }
         | 
| 54 | 
            -
              end
         | 
| 55 | 
            -
            end
         | 
| 56 | 
            -
             | 
| 57 | 
            -
            puts "\nBenchmarking READ performance (#{N} keys)..."
         | 
| 58 | 
            -
            Benchmark.bm(20) do |x|
         | 
| 59 | 
            -
              x.report("MemoryStore read:") do
         | 
| 60 | 
            -
                N.times { |i| memory_store.read("key#{i}") }
         | 
| 61 | 
            -
              end
         | 
| 62 | 
            -
             | 
| 63 | 
            -
              x.report("Pogocache read:") do
         | 
| 64 | 
            -
                N.times { |i| pogocache_store.get("key#{i}") }
         | 
| 65 | 
            -
              end
         | 
| 66 | 
            -
            end
         | 
| 67 | 
            -
             | 
| 68 | 
            -
            puts "Benchmarking WRITE performance (#{N} keys)..."
         | 
| 69 | 
            -
            Benchmark.memory do |x|
         | 
| 70 | 
            -
              x.report("MemoryStore write:") do
         | 
| 71 | 
            -
                N.times { |i| memory_store.write("key#{i}", { number: i, value: nil}) }
         | 
| 72 | 
            -
              end
         | 
| 73 | 
            -
             | 
| 74 | 
            -
              x.report("Pogocache write:") do
         | 
| 75 | 
            -
                N.times { |i| pogocache_store.set("key#{i}", { number: i, value: nil}) }
         | 
| 76 | 
            -
              end
         | 
| 77 | 
            -
            end
         | 
| 78 | 
            -
             | 
| 79 | 
            -
            puts "\nBenchmarking READ performance (#{N} keys)..."
         | 
| 80 | 
            -
            Benchmark.memory do |x|
         | 
| 81 | 
            -
              x.report("MemoryStore read:") do
         | 
| 82 | 
            -
                N.times { |i| memory_store.read("key#{i}") }
         | 
| 83 | 
            -
              end
         | 
| 84 | 
            -
             | 
| 85 | 
            -
              x.report("Pogocache read:") do
         | 
| 86 | 
            -
                N.times { |i| pogocache_store.get("key#{i}") }
         | 
| 87 | 
            -
              end
         | 
| 88 | 
            -
            end
         | 
| 39 | 
            +
            See [pogocache_spec.rb](spec/pogocache_spec.rb) and [pogocache.h](ext/pogocache_ruby/pogocache.h) for details.
         | 
| 89 40 |  | 
| 90 | 
            -
             | 
| 41 | 
            +
            ## Benchmark
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            [benchmark.rb](benchmark.rb)
         | 
| 91 44 |  | 
| 92 45 | 
             
            ```
         | 
| 93 46 | 
             
            Benchmarking WRITE performance (100000 keys)...
         | 
| 94 47 | 
             
                                       user     system      total        real
         | 
| 95 | 
            -
            MemoryStore write:     0. | 
| 96 | 
            -
            Pogocache write:       0. | 
| 48 | 
            +
            MemoryStore write:     0.526285   0.020191   0.546476 (  0.546561)
         | 
| 49 | 
            +
            Pogocache write:       0.087404   0.003957   0.091361 (  0.091385)
         | 
| 97 50 |  | 
| 98 51 | 
             
            Benchmarking READ performance (100000 keys)...
         | 
| 99 52 | 
             
                                       user     system      total        real
         | 
| 100 | 
            -
            MemoryStore read:      0. | 
| 101 | 
            -
            Pogocache read:        0. | 
| 53 | 
            +
            MemoryStore read:      0.302697   0.004301   0.306998 (  0.307099)
         | 
| 54 | 
            +
            Pogocache read:        0.104694   0.000000   0.104694 (  0.104700)
         | 
| 102 55 |  | 
| 103 | 
            -
            Benchmarking  | 
| 56 | 
            +
            Benchmarking memory performance (100000 keys)...
         | 
| 104 57 | 
             
            Calculating -------------------------------------
         | 
| 105 | 
            -
             | 
| 106 | 
            -
                                     2. | 
| 107 | 
            -
                                    50.000  strings (    50.000  retained)
         | 
| 108 | 
            -
                Pogocache write:    54.396M memsize (     0.000  retained)
         | 
| 109 | 
            -
                                   599.990k objects (     0.000  retained)
         | 
| 58 | 
            +
                    MemoryStore:   232.000M memsize (     8.000M retained)
         | 
| 59 | 
            +
                                     2.200M objects (   100.000k retained)
         | 
| 110 60 | 
             
                                    50.000  strings (     0.000  retained)
         | 
| 111 | 
            -
             | 
| 112 | 
            -
             | 
| 113 | 
            -
            Calculating -------------------------------------
         | 
| 114 | 
            -
               MemoryStore read:   116.000M memsize (     0.000  retained)
         | 
| 115 | 
            -
                                     1.200M objects (     0.000  retained)
         | 
| 116 | 
            -
                                    50.000  strings (     0.000  retained)
         | 
| 117 | 
            -
                 Pogocache read:    71.192M memsize (     0.000  retained)
         | 
| 118 | 
            -
                                   899.990k objects (     0.000  retained)
         | 
| 61 | 
            +
                      Pogocache:    52.000M memsize (     0.000  retained)
         | 
| 62 | 
            +
                                   700.000k objects (     0.000  retained)
         | 
| 119 63 | 
             
                                    50.000  strings (     0.000  retained)
         | 
| 120 64 |  | 
| 121 65 | 
             
            ```
         | 
| 66 | 
            +
             | 
| 67 | 
            +
            ## License
         | 
| 68 | 
            +
             | 
| 69 | 
            +
            This gem uses [Pogocache](https://pogocache.com). Pogocache is free & open source software released under the terms of the AGPL license. The Pogocache source code was written and copyrighted by [Polypoint Labs, LLC](https://polypointlabs.com/). 
         | 
| 70 | 
            +
             | 
| 71 | 
            +
            For alternative licensing options, please contact them at licensing@polypointlabs.com.
         | 
    
        data/benchmark.rb
    ADDED
    
    | @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            require "pogocache-ruby"
         | 
| 2 | 
            +
            require "active_support"
         | 
| 3 | 
            +
            require "active_support/cache"
         | 
| 4 | 
            +
            require "benchmark"
         | 
| 5 | 
            +
            require "benchmark/memory"
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            memory_store = ActiveSupport::Cache::MemoryStore.new
         | 
| 8 | 
            +
            pogocache_store = Pogocache::Cache.new
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            N = 100_000
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            puts "Benchmarking WRITE performance (#{N} keys)..."
         | 
| 13 | 
            +
            Benchmark.bm(20) do |x|
         | 
| 14 | 
            +
              x.report("MemoryStore write:") do
         | 
| 15 | 
            +
                N.times { |i| memory_store.write(i, i) }
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              x.report("Pogocache write:") do
         | 
| 19 | 
            +
                N.times { |i| pogocache_store.set(i, i) }
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            puts "\nBenchmarking READ performance (#{N} keys)..."
         | 
| 24 | 
            +
            Benchmark.bm(20) do |x|
         | 
| 25 | 
            +
              x.report("MemoryStore read:") do
         | 
| 26 | 
            +
                N.times { |i| memory_store.read(i) }
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              x.report("Pogocache read:") do
         | 
| 30 | 
            +
                N.times { |i| pogocache_store.get(i) }
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
            end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            puts "\nBenchmarking memory performance (#{N} keys)..."
         | 
| 35 | 
            +
            Benchmark.memory do |x|
         | 
| 36 | 
            +
              x.report("MemoryStore:") do
         | 
| 37 | 
            +
                N.times { |i| memory_store.write(i, i) }
         | 
| 38 | 
            +
                N.times { |i| memory_store.read(i) }
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              x.report("Pogocache:") do
         | 
| 42 | 
            +
                N.times { |i| pogocache_store.set(i, i) }
         | 
| 43 | 
            +
                N.times { |i| pogocache_store.get(i) }
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
            end
         | 
    
        data/lib/pogocache-ruby/cache.rb
    CHANGED
    
    | @@ -18,9 +18,7 @@ class Pogocache::Cache | |
| 18 18 | 
             
                end
         | 
| 19 19 | 
             
              end
         | 
| 20 20 |  | 
| 21 | 
            -
              def delete(key)
         | 
| 22 | 
            -
                @extension.delete(encode(key))
         | 
| 23 | 
            -
              end
         | 
| 21 | 
            +
              def delete(key) = @extension.delete(encode(key))
         | 
| 24 22 |  | 
| 25 23 | 
             
              def [](key)
         | 
| 26 24 | 
             
                get(key)
         | 
| @@ -37,22 +35,37 @@ class Pogocache::Cache | |
| 37 35 | 
             
                block&.call
         | 
| 38 36 | 
             
              end
         | 
| 39 37 |  | 
| 40 | 
            -
              def  | 
| 41 | 
            -
                 | 
| 38 | 
            +
              def increment(key)
         | 
| 39 | 
            +
                value = get(key)&.to_i
         | 
| 40 | 
            +
                if value
         | 
| 41 | 
            +
                  set(key, value + 1)
         | 
| 42 | 
            +
                  value + 1
         | 
| 43 | 
            +
                else
         | 
| 44 | 
            +
                  set(key, 1)
         | 
| 45 | 
            +
                  1
         | 
| 46 | 
            +
                end
         | 
| 42 47 | 
             
              end
         | 
| 43 | 
            -
              alias_method(:size, :count)
         | 
| 44 48 |  | 
| 45 | 
            -
              def  | 
| 46 | 
            -
                 | 
| 49 | 
            +
              def decrement(key)
         | 
| 50 | 
            +
                value = get(key)&.to_i
         | 
| 51 | 
            +
                if value
         | 
| 52 | 
            +
                  set(key, value - 1)
         | 
| 53 | 
            +
                  value - 1
         | 
| 54 | 
            +
                else
         | 
| 55 | 
            +
                  set(key, 1)
         | 
| 56 | 
            +
                  1
         | 
| 57 | 
            +
                end
         | 
| 47 58 | 
             
              end
         | 
| 48 59 |  | 
| 49 | 
            -
              def  | 
| 50 | 
            -
                @extension.clear
         | 
| 51 | 
            -
              end
         | 
| 60 | 
            +
              def count = @extension.count
         | 
| 52 61 |  | 
| 53 | 
            -
              def  | 
| 54 | 
            -
             | 
| 55 | 
            -
               | 
| 62 | 
            +
              def size = count
         | 
| 63 | 
            +
             | 
| 64 | 
            +
              def bytesize = @extension.size
         | 
| 65 | 
            +
             | 
| 66 | 
            +
              def clear = @extension.clear
         | 
| 67 | 
            +
             | 
| 68 | 
            +
              def sweep = @extension.sweep
         | 
| 56 69 |  | 
| 57 70 | 
             
              def each(opts = {}, &block)
         | 
| 58 71 | 
             
                if block_given?
         | 
| @@ -70,12 +83,32 @@ class Pogocache::Cache | |
| 70 83 |  | 
| 71 84 | 
             
              def nshards = @extension.nshards
         | 
| 72 85 |  | 
| 73 | 
            -
               | 
| 86 | 
            +
              def cleanup(options = {}) = @extension.sweep
         | 
| 74 87 |  | 
| 75 | 
            -
              def  | 
| 76 | 
            -
                Marshal.dump(obj)
         | 
| 88 | 
            +
              def prune(options = {})
         | 
| 77 89 | 
             
              end
         | 
| 78 90 |  | 
| 91 | 
            +
              def pruning?
         | 
| 92 | 
            +
                false
         | 
| 93 | 
            +
              end
         | 
| 94 | 
            +
             | 
| 95 | 
            +
              def delete_matched(matcher, options = {})
         | 
| 96 | 
            +
                @extension.each do |e|
         | 
| 97 | 
            +
                  if decode(e[:key]).to_s.match(matcher)
         | 
| 98 | 
            +
                    Pogocache::ITER_DELETE # standard:disable Lint/Void
         | 
| 99 | 
            +
                  else
         | 
| 100 | 
            +
                    Pogocache::ITER_CONTINUE # standard:disable Lint/Void
         | 
| 101 | 
            +
                  end
         | 
| 102 | 
            +
                end
         | 
| 103 | 
            +
              end
         | 
| 104 | 
            +
             | 
| 105 | 
            +
              def synchronize
         | 
| 106 | 
            +
              end
         | 
| 107 | 
            +
             | 
| 108 | 
            +
              private
         | 
| 109 | 
            +
             | 
| 110 | 
            +
              def encode(obj) = Marshal.dump(obj)
         | 
| 111 | 
            +
             | 
| 79 112 | 
             
              def decode(str)
         | 
| 80 113 | 
             
                return nil if str.nil? || str.empty?
         | 
| 81 114 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: pogocache-ruby
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.2.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - heming
         | 
| @@ -91,6 +91,7 @@ files: | |
| 91 91 | 
             
            - LICENSE
         | 
| 92 92 | 
             
            - README.md
         | 
| 93 93 | 
             
            - Rakefile
         | 
| 94 | 
            +
            - benchmark.rb
         | 
| 94 95 | 
             
            - ext/pogocache_ruby/extconf.rb
         | 
| 95 96 | 
             
            - ext/pogocache_ruby/pogocache.c
         | 
| 96 97 | 
             
            - ext/pogocache_ruby/pogocache.h
         |