Closed francois closed 5 months ago
I essentially ran the following:
rails new --database=sqlite3 bundle add litestack # edit config/environments/development.rb # replaced `:memory_store` with `config.cache_store = :litecache, {path: Litesupport.root(Rails.env).join("cache.sqlite3")}` (see below)
With the Rails server NOT running, I opened a console and ran the following two commands:
Rails.cache.write('foo', 'bar') #=> true Rails.cache.read('foo') #=> nil
When I open the db/development/cache.sqlite3 file and query the data table, I can see the key added, but the value is always null.
db/development/cache.sqlite3
data
null
# config/environments/development.rb Rails.application.configure do # ... config.cache_store = :litecache, {path: Litesupport.root(Rails.env).join("cache.sqlite3")} end
$ tree db db ├── seeds.rb └── test 2 directories, 1 file
$ bin/rails console Loading development environment (Rails 7.1.3.2) irb(main):001> Rails.cache => #<ActiveSupport::Cache::Litecache:0x00000001213088e8 @cache= #<Litecache:0x000000012132bde8 @bgthread=#<Thread:0x0000000121327dd8 /Users/francois/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/litestack-0.4.3/lib/litestack/litecache.rb:248 sleep>, @conn=#<Litesupport::Pool:0x0000000121308758 @block=#<Proc:0x000000012132bb18 /Users/francois/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/litestack-0.4.3/lib/litestack/litesupport.rb:235>, @count=1, @mutex=#<Litesupport::Mutex:0x000000012132baa0 @mutex=#<Thread::Mutex:0x000000012132ba78>>, @resources=#<Thread::Queue:0x000000012132baf0>>, @expires_in=2592000, @logger=#<Logger:0x0000000121307fd8 @default_formatter=#<Logger::Formatter:0x0000000121327e50 @datetime_format=nil>, @formatter=nil, @level=0, @level_override={}, @logdev=nil, @progname=nil>, @options={:path=>#<Pathname:./db/development/cache.sqlite3>, :config_path=>"./litecache.yml", :sync=>0, :expiry=>2592000, :size=>134217728, :mmap_size=>134217728, :min_size=>8388608, :return_full_record=>true, :sleep_interval=>30, :metrics=>false, :compress=>true, :compress_threshold=>1024, :logger=>nil}, @running=true>, @coder=#<ActiveSupport::Cache::Coder:0x000000012132beb0 @compressor=Zlib, @legacy_serializer=false, @serializer=ActiveSupport::Cache::SerializerWithFallback::Marshal71WithFallback>, @coder_supports_compression=true, @options={:path=>#<Pathname:./db/development/cache.sqlite3>, :compress=>true, :compress_threshold=>1024, :return_full_record=>true}> irb(main):002> Rails.cache.write('foo', 'value') => true irb(main):003> Rails.cache.read('foo') => nil
$ tree db db ├── development │ ├── cache.sqlite3 │ ├── queue.sqlite3 │ ├── queue.sqlite3-shm │ └── queue.sqlite3-wal ├── production ├── seeds.rb └── test 4 directories, 5 files $ sqlite3 db/development/cache.sqlite3 'select * from data' foo||1711335886|1711335886
From the Rails console, if I #instance_variable_get the Litecache instance, then I can set and get values correctly:
#instance_variable_get
Litecache
$ bin/rails c cache = Rails.cache.instance_variable_get(:@cache) #=> #<Litecache:0x000000012b471a18 cache.set('bar', 'some value') #=> true cache.get('bar') #=> "some value" $ sqlite3 db/development/cache.sqlite3 'select * from data' bar|some value|1713928160|1711336160
I'm certainly doing something wrong... what is my error?
Ah, I see! I have found 951fdf5077dbf47e6143d74c579865a9fc728aa9 which fixes the issue. 0.4.3 was too "old".
I essentially ran the following:
With the Rails server NOT running, I opened a console and ran the following two commands:
When I open the
db/development/cache.sqlite3
file and query thedata
table, I can see the key added, but the value is alwaysnull
.From the Rails console, if I
#instance_variable_get
theLitecache
instance, then I can set and get values correctly:Gemfile, Gemfile.lock
### Gemfile ```ruby source "https://rubygems.org" ruby "3.3.0" gem "bootsnap", require: false gem "capybara", group: :test gem "debug", platforms: %i[mri windows], groups: %i[development test] gem "image_processing", "~> 1.2" gem "importmap-rails" gem "litestack" gem "propshaft" gem "puma", ">= 5.0" gem "rails", "~> 7.1.3", ">= 7.1.3.2" gem "selenium-webdriver", group: :test gem "sqlite3", "~> 1.4" gem "standardrb", group: :development gem "stimulus-rails" gem "tailwindcss-rails" gem "turbo-rails" gem "tzinfo-data", platforms: %i[windows jruby] gem "web-console", group: :development ``` ### Gemfile.lock ``` GEM remote: https://rubygems.org/ specs: actioncable (7.1.3.2) actionpack (= 7.1.3.2) activesupport (= 7.1.3.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) actionmailbox (7.1.3.2) actionpack (= 7.1.3.2) activejob (= 7.1.3.2) activerecord (= 7.1.3.2) activestorage (= 7.1.3.2) activesupport (= 7.1.3.2) mail (>= 2.7.1) net-imap net-pop net-smtp actionmailer (7.1.3.2) actionpack (= 7.1.3.2) actionview (= 7.1.3.2) activejob (= 7.1.3.2) activesupport (= 7.1.3.2) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.2) actionpack (7.1.3.2) actionview (= 7.1.3.2) activesupport (= 7.1.3.2) nokogiri (>= 1.8.5) racc rack (>= 2.2.4) rack-session (>= 1.0.1) rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) actiontext (7.1.3.2) actionpack (= 7.1.3.2) activerecord (= 7.1.3.2) activestorage (= 7.1.3.2) activesupport (= 7.1.3.2) globalid (>= 0.6.0) nokogiri (>= 1.8.5) actionview (7.1.3.2) activesupport (= 7.1.3.2) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) activejob (7.1.3.2) activesupport (= 7.1.3.2) globalid (>= 0.3.6) activemodel (7.1.3.2) activesupport (= 7.1.3.2) activerecord (7.1.3.2) activemodel (= 7.1.3.2) activesupport (= 7.1.3.2) timeout (>= 0.4.0) activestorage (7.1.3.2) actionpack (= 7.1.3.2) activejob (= 7.1.3.2) activerecord (= 7.1.3.2) activesupport (= 7.1.3.2) marcel (~> 1.0) activesupport (7.1.3.2) base64 bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) minitest (>= 5.1) mutex_m tzinfo (~> 2.0) addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) ast (2.4.2) base64 (0.2.0) bigdecimal (3.1.7) bindex (0.8.1) bootsnap (1.18.3) msgpack (~> 1.2) builder (3.2.4) capybara (3.40.0) addressable matrix mini_mime (>= 0.1.3) nokogiri (~> 1.11) rack (>= 1.6.0) rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) concurrent-ruby (1.2.3) connection_pool (2.4.1) crass (1.0.6) date (3.3.4) debug (1.9.1) irb (~> 1.10) reline (>= 0.3.8) drb (2.2.1) erubi (1.12.0) ffi (1.16.3) globalid (1.2.1) activesupport (>= 6.1) hanami-router (0.6.2) hanami-utils (~> 0.7) http_router (~> 0.11) hanami-utils (0.9.2) http_router (0.11.2) rack (>= 1.0.0) url_mount (~> 0.2.1) i18n (1.14.4) concurrent-ruby (~> 1.0) image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) importmap-rails (2.0.1) actionpack (>= 6.0.0) activesupport (>= 6.0.0) railties (>= 6.0.0) io-console (0.7.2) irb (1.12.0) rdoc reline (>= 0.4.2) json (2.7.1) language_server-protocol (3.17.0.3) lint_roller (1.1.0) litestack (0.4.3) erubi hanami-router oj rack sqlite3 tilt loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) mini_mime (>= 0.1.1) net-imap net-pop net-smtp marcel (1.0.4) matrix (0.4.2) mini_magick (4.12.0) mini_mime (1.1.5) minitest (5.22.3) msgpack (1.7.2) mutex_m (0.2.0) net-imap (0.4.10) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.2) timeout net-smtp (0.4.0.1) net-protocol nio4r (2.7.1) nokogiri (1.16.3-aarch64-linux) racc (~> 1.4) nokogiri (1.16.3-arm-linux) racc (~> 1.4) nokogiri (1.16.3-arm64-darwin) racc (~> 1.4) nokogiri (1.16.3-x86-linux) racc (~> 1.4) nokogiri (1.16.3-x86_64-darwin) racc (~> 1.4) nokogiri (1.16.3-x86_64-linux) racc (~> 1.4) oj (3.16.3) bigdecimal (>= 3.0) parallel (1.24.0) parser (3.3.0.5) ast (~> 2.4.1) racc propshaft (0.8.0) actionpack (>= 7.0.0) activesupport (>= 7.0.0) rack railties (>= 7.0.0) psych (5.1.2) stringio public_suffix (5.0.4) puma (6.4.2) nio4r (~> 2.0) racc (1.7.3) rack (3.0.10) rack-session (2.0.0) rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) rackup (2.1.0) rack (>= 3) webrick (~> 1.8) rails (7.1.3.2) actioncable (= 7.1.3.2) actionmailbox (= 7.1.3.2) actionmailer (= 7.1.3.2) actionpack (= 7.1.3.2) actiontext (= 7.1.3.2) actionview (= 7.1.3.2) activejob (= 7.1.3.2) activemodel (= 7.1.3.2) activerecord (= 7.1.3.2) activestorage (= 7.1.3.2) activesupport (= 7.1.3.2) bundler (>= 1.15.0) railties (= 7.1.3.2) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) railties (7.1.3.2) actionpack (= 7.1.3.2) activesupport (= 7.1.3.2) irb rackup (>= 1.0.0) rake (>= 12.2) thor (~> 1.0, >= 1.2.2) zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.1.0) rdoc (6.6.3.1) psych (>= 4.0.0) regexp_parser (2.9.0) reline (0.4.3) io-console (~> 0.5) rexml (3.2.6) rubocop (1.62.1) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.31.2) parser (>= 3.3.0.4) rubocop-performance (1.20.2) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (1.13.0) ruby-vips (2.2.1) ffi (~> 1.12) rubyzip (2.3.2) selenium-webdriver (4.18.1) base64 (~> 0.2) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) sqlite3 (1.7.3-aarch64-linux) sqlite3 (1.7.3-arm-linux) sqlite3 (1.7.3-arm64-darwin) sqlite3 (1.7.3-x86-linux) sqlite3 (1.7.3-x86_64-darwin) sqlite3 (1.7.3-x86_64-linux) standard (1.35.1) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.0) rubocop (~> 1.62.0) standard-custom (~> 1.0.0) standard-performance (~> 1.3) standard-custom (1.0.2) lint_roller (~> 1.0) rubocop (~> 1.50) standard-performance (1.3.1) lint_roller (~> 1.1) rubocop-performance (~> 1.20.2) standardrb (1.0.1) standard stimulus-rails (1.3.3) railties (>= 6.0.0) stringio (3.1.0) tailwindcss-rails (2.3.0) railties (>= 6.0.0) tailwindcss-rails (2.3.0-aarch64-linux) railties (>= 6.0.0) tailwindcss-rails (2.3.0-arm-linux) railties (>= 6.0.0) tailwindcss-rails (2.3.0-arm64-darwin) railties (>= 6.0.0) tailwindcss-rails (2.3.0-x86_64-darwin) railties (>= 6.0.0) tailwindcss-rails (2.3.0-x86_64-linux) railties (>= 6.0.0) thor (1.3.1) tilt (2.3.0) timeout (0.4.1) turbo-rails (2.0.5) actionpack (>= 6.0.0) activejob (>= 6.0.0) railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) url_mount (0.2.1) rack web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) webrick (1.8.1) websocket (1.2.10) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) zeitwerk (2.6.13) PLATFORMS aarch64-linux arm-linux arm64-darwin x86-linux x86_64-darwin x86_64-linux DEPENDENCIES bootsnap capybara debug image_processing (~> 1.2) importmap-rails litestack propshaft puma (>= 5.0) rails (~> 7.1.3, >= 7.1.3.2) selenium-webdriver sqlite3 (~> 1.4) standardrb stimulus-rails tailwindcss-rails turbo-rails tzinfo-data web-console RUBY VERSION ruby 3.3.0p0 BUNDLED WITH 2.5.3 ```I'm certainly doing something wrong... what is my error?