/
activesupport-generated.rbs
12672 lines (10526 loc) · 440 KB
/
activesupport-generated.rbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# The generated code is based on Ruby on Rails source code
# You can find the license of Ruby on Rails from following.
#Copyright (c) 2005-2019 David Heinemeier Hansson
#
#Permission is hereby granted, free of charge, to any person obtaining
#a copy of this software and associated documentation files (the
#"Software"), to deal in the Software without restriction, including
#without limitation the rights to use, copy, modify, merge, publish,
#distribute, sublicense, and/or sell copies of the Software, and to
#permit persons to whom the Software is furnished to do so, subject to
#the following conditions:
#
#The above copyright notice and this permission notice shall be
#included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
#MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
#LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
#OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
#WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
module ActiveSupport
# Actionable errors let's you define actions to resolve an error.
#
# To make an error actionable, include the <tt>ActiveSupport::ActionableError</tt>
# module and invoke the +action+ class macro to define the action. An action
# needs a name and a block to execute.
module ActionableError
extend Concern
class NonActionable < StandardError
end
def self.actions: (untyped error) -> untyped
def self.dispatch: (untyped error, untyped name) -> untyped
module ClassMethods
# Defines an action that can resolve the error.
#
# class PendingMigrationError < MigrationError
# include ActiveSupport::ActionableError
#
# action "Run pending migrations" do
# ActiveRecord::Tasks::DatabaseTasks.migrate
# end
# end
def action: (untyped name) { () -> untyped } -> untyped
end
end
end
module ActiveSupport
# Wrapping an array in an +ArrayInquirer+ gives a friendlier way to check
# its string-like contents:
#
# variants = ActiveSupport::ArrayInquirer.new([:phone, :tablet])
#
# variants.phone? # => true
# variants.tablet? # => true
# variants.desktop? # => false
class ArrayInquirer[T] < Array[T]
# Passes each element of +candidates+ collection to ArrayInquirer collection.
# The method returns true if any element from the ArrayInquirer collection
# is equal to the stringified or symbolized form of any element in the +candidates+ collection.
#
# If +candidates+ collection is not given, method returns true.
#
# variants = ActiveSupport::ArrayInquirer.new([:phone, :tablet])
#
# variants.any? # => true
# variants.any?(:phone, :tablet) # => true
# variants.any?('phone', 'desktop') # => true
# variants.any?(:desktop, :watch) # => false
def any?: (*untyped candidates) -> untyped
private
def respond_to_missing?: (untyped name, ?bool include_private) -> untyped
def method_missing: (untyped name, *untyped args) -> untyped
end
end
module ActiveSupport
# Backtraces often include many lines that are not relevant for the context
# under review. This makes it hard to find the signal amongst the backtrace
# noise, and adds debugging time. With a BacktraceCleaner, filters and
# silencers are used to remove the noisy lines, so that only the most relevant
# lines remain.
#
# Filters are used to modify lines of data, while silencers are used to remove
# lines entirely. The typical filter use case is to remove lengthy path
# information from the start of each line, and view file paths relevant to the
# app directory instead of the file system root. The typical silencer use case
# is to exclude the output of a noisy library from the backtrace, so that you
# can focus on the rest.
#
# bc = ActiveSupport::BacktraceCleaner.new
# bc.add_filter { |line| line.gsub(Rails.root.to_s, '') } # strip the Rails.root prefix
# bc.add_silencer { |line| line =~ /puma|rubygems/ } # skip any lines from puma or rubygems
# bc.clean(exception.backtrace) # perform the cleanup
#
# To reconfigure an existing BacktraceCleaner (like the default one in Rails)
# and show as much data as possible, you can always call
# <tt>BacktraceCleaner#remove_silencers!</tt>, which will restore the
# backtrace to a pristine state. If you need to reconfigure an existing
# BacktraceCleaner so that it does not filter or modify the paths of any lines
# of the backtrace, you can call <tt>BacktraceCleaner#remove_filters!</tt>
# These two methods will give you a completely untouched backtrace.
#
# Inspired by the Quiet Backtrace gem by thoughtbot.
class BacktraceCleaner
def initialize: () -> untyped
# Returns the backtrace after all filters and silencers have been run
# against it. Filters run first, then silencers.
def clean: (untyped backtrace, ?::Symbol kind) -> untyped
alias filter clean
# Adds a filter from the block provided. Each line in the backtrace will be
# mapped against this filter.
#
# # Will turn "/my/rails/root/app/models/person.rb" into "/app/models/person.rb"
# backtrace_cleaner.add_filter { |line| line.gsub(Rails.root, '') }
def add_filter: () { () -> untyped } -> untyped
# Adds a silencer from the block provided. If the silencer returns +true+
# for a given line, it will be excluded from the clean backtrace.
#
# # Will reject all lines that include the word "puma", like "/gems/puma/server.rb" or "/app/my_puma_server/rb"
# backtrace_cleaner.add_silencer { |line| line =~ /puma/ }
def add_silencer: () { () -> untyped } -> untyped
# Removes all silencers, but leaves in the filters. Useful if your
# context of debugging suddenly expands as you suspect a bug in one of
# the libraries you use.
def remove_silencers!: () -> untyped
# Removes all filters, but leaves in the silencers. Useful if you suddenly
# need to see entire filepaths in the backtrace that you had already
# filtered out.
def remove_filters!: () -> untyped
private
FORMATTED_GEMS_PATTERN: untyped
def add_gem_filter: () -> (nil | untyped)
def add_gem_silencer: () -> untyped
def add_stdlib_silencer: () -> untyped
def filter_backtrace: (untyped backtrace) -> untyped
def silence: (untyped backtrace) -> untyped
def noise: (untyped backtrace) -> untyped
end
end
module ActiveSupport
module Benchmarkable
# Allows you to measure the execution time of a block in a template and
# records the result to the log. Wrap this block around expensive operations
# or possible bottlenecks to get a time reading for the operation. For
# example, let's say you thought your file processing method was taking too
# long; you could wrap it in a benchmark block.
#
# <% benchmark 'Process data files' do %>
# <%= expensive_files_operation %>
# <% end %>
#
# That would add something like "Process data files (345.2ms)" to the log,
# which you can then use to compare timings when optimizing your code.
#
# You may give an optional logger level (<tt>:debug</tt>, <tt>:info</tt>,
# <tt>:warn</tt>, <tt>:error</tt>) as the <tt>:level</tt> option. The
# default logger level value is <tt>:info</tt>.
#
# <% benchmark 'Low-level files', level: :debug do %>
# <%= lowlevel_files_operation %>
# <% end %>
#
# Finally, you can pass true as the third argument to silence all log
# activity (other than the timing information) from inside the block. This
# is great for boiling down a noisy block to just a single statement that
# produces one log line:
#
# <% benchmark 'Process data files', level: :info, silence: true do %>
# <%= expensive_and_chatty_files_operation %>
# <% end %>
def benchmark: (?::String message, ?::Hash[untyped, untyped] options) { () -> untyped } -> untyped
end
end
module ActiveSupport
module Cache
# A cache store implementation which stores everything on the filesystem.
#
# FileStore implements the Strategy::LocalCache strategy which implements
# an in-memory cache inside of a block.
class FileStore < Store
attr_reader cache_path: untyped
DIR_FORMATTER: ::String
FILENAME_MAX_SIZE: ::Integer
FILEPATH_MAX_SIZE: ::Integer
# max filename size on file system is 255, minus room for timestamp and random characters appended by Tempfile (used by atomic write)
# max is 1024, plus some room
GITKEEP_FILES: untyped
def initialize: (untyped cache_path, ?untyped? options) -> untyped
# Advertise cache versioning support.
def self.supports_cache_versioning?: () -> ::TrueClass
# Deletes all items from the cache. In this case it deletes all the entries in the specified
# file store directory except for .keep or .gitkeep. Be careful which directory is specified in your
# config file when using +FileStore+ because everything in that directory will be deleted.
def clear: (?untyped? options) -> untyped
# Preemptively iterates through all stored keys and removes the ones which have expired.
def cleanup: (?untyped? options) -> untyped
# Increments an already existing integer value that is stored in the cache.
# If the key is not found nothing is done.
def increment: (untyped name, ?::Integer amount, ?untyped? options) -> untyped
# Decrements an already existing integer value that is stored in the cache.
# If the key is not found nothing is done.
def decrement: (untyped name, ?::Integer amount, ?untyped? options) -> untyped
def delete_matched: (untyped matcher, ?untyped? options) -> untyped
private
def read_entry: (untyped key, **untyped options) -> untyped
def write_entry: (untyped key, untyped entry, **untyped options) -> (::FalseClass | ::TrueClass)
def delete_entry: (untyped key, **untyped options) -> untyped
# Lock a file for a block so only one process can modify it at a time.
def lock_file: (untyped file_name) { () -> untyped } -> untyped
# Translate a key into a file path.
def normalize_key: (untyped key, untyped options) -> untyped
# Translate a file path into a key.
def file_path_key: (untyped path) -> untyped
# Delete empty directories in the cache.
def delete_empty_directories: (untyped dir) -> (nil | untyped)
# Make sure a file path's directories exist.
def ensure_cache_path: (untyped path) -> untyped
def search_dir: (untyped dir) { () -> untyped } -> (nil | untyped)
# Modifies the amount of an already existing integer value that is stored in the cache.
# If the key is not found nothing is done.
def modify_value: (untyped name, untyped amount, untyped options) -> untyped
end
end
end
module ActiveSupport
module Cache
# A cache store implementation which stores data in Memcached:
# https://memcached.org
#
# This is currently the most popular cache store for production websites.
#
# Special features:
# - Clustering and load balancing. One can specify multiple memcached servers,
# and MemCacheStore will load balance between all available servers. If a
# server goes down, then MemCacheStore will ignore it until it comes back up.
#
# MemCacheStore implements the Strategy::LocalCache strategy which implements
# an in-memory cache inside of a block.
class MemCacheStore < Store
module LocalCacheWithRaw
private
def write_entry: (untyped key, untyped entry, **untyped options) -> untyped
end
# Advertise cache versioning support.
def self.supports_cache_versioning?: () -> ::TrueClass
ESCAPE_KEY_CHARS: untyped
def self.build_mem_cache: (*untyped addresses) -> untyped
# Creates a new MemCacheStore object, with the given memcached server
# addresses. Each address is either a host name, or a host-with-port string
# in the form of "host_name:port". For example:
#
# ActiveSupport::Cache::MemCacheStore.new("localhost", "server-downstairs.localnetwork:8229")
#
# If no addresses are specified, then MemCacheStore will connect to
# localhost port 11211 (the default memcached port).
def initialize: (*untyped addresses) -> untyped
# Increment a cached value. This method uses the memcached incr atomic
# operator and can only be used on values written with the :raw option.
# Calling it on a value not stored with :raw will initialize that value
# to zero.
def increment: (untyped name, ?::Integer amount, ?untyped? options) -> untyped
# Decrement a cached value. This method uses the memcached decr atomic
# operator and can only be used on values written with the :raw option.
# Calling it on a value not stored with :raw will initialize that value
# to zero.
def decrement: (untyped name, ?::Integer amount, ?untyped? options) -> untyped
# Clear the entire cache on all memcached servers. This method should
# be used with care when shared cache is being used.
def clear: (?untyped? options) -> untyped
# Get the statistics from the memcached servers.
def stats: () -> untyped
private
# Read an entry from the cache.
def read_entry: (untyped key, **untyped options) -> untyped
# Write an entry to the cache.
def write_entry: (untyped key, untyped entry, **untyped options) -> untyped
# Reads multiple entries from the cache implementation.
def read_multi_entries: (untyped names, **untyped options) -> untyped
# Delete an entry from the cache.
def delete_entry: (untyped key, **untyped options) -> untyped
# Memcache keys are binaries. So we need to force their encoding to binary
# before applying the regular expression to ensure we are escaping all
# characters properly.
def normalize_key: (untyped key, untyped options) -> untyped
def deserialize_entry: (untyped entry) -> untyped
def rescue_error_with: (untyped fallback) { () -> untyped } -> untyped
end
end
end
module ActiveSupport
module Cache
# A cache store implementation which stores everything into memory in the
# same process. If you're running multiple Ruby on Rails server processes
# (which is the case if you're using Phusion Passenger or puma clustered mode),
# then this means that Rails server process instances won't be able
# to share cache data with each other and this may not be the most
# appropriate cache in that scenario.
#
# This cache has a bounded size specified by the :size options to the
# initializer (default is 32Mb). When the cache exceeds the allotted size,
# a cleanup will occur which tries to prune the cache down to three quarters
# of the maximum size by removing the least recently used entries.
#
# MemoryStore is thread-safe.
class MemoryStore < Store
def initialize: (?untyped? options) -> untyped
# Advertise cache versioning support.
def self.supports_cache_versioning?: () -> ::TrueClass
# Delete all data stored in a given cache store.
def clear: (?untyped? options) -> untyped
# Preemptively iterates through all stored keys and removes the ones which have expired.
def cleanup: (?untyped? options) -> untyped
# To ensure entries fit within the specified memory prune the cache by removing the least
# recently accessed entries.
def prune: (untyped target_size, ?untyped? max_time) -> (nil | untyped)
# Returns true if the cache is currently being pruned.
def pruning?: () -> untyped
# Increment an integer value in the cache.
def increment: (untyped name, ?::Integer amount, ?untyped? options) -> untyped
# Decrement an integer value in the cache.
def decrement: (untyped name, ?::Integer amount, ?untyped? options) -> untyped
# Deletes cache entries if the cache key matches a given pattern.
def delete_matched: (untyped matcher, ?untyped? options) -> untyped
def inspect: () -> ::String
def synchronize: () { () -> untyped } -> untyped
private
PER_ENTRY_OVERHEAD: ::Integer
def cached_size: (untyped key, untyped entry) -> untyped
def read_entry: (untyped key, **untyped options) -> untyped
def write_entry: (untyped key, untyped entry, **untyped options) -> (::FalseClass | untyped)
def delete_entry: (untyped key, **untyped options) -> untyped
def modify_value: (untyped name, untyped amount, untyped options) -> untyped
end
end
end
module ActiveSupport
module Cache
# A cache store implementation which doesn't actually store anything. Useful in
# development and test environments where you don't want caching turned on but
# need to go through the caching interface.
#
# This cache does implement the local cache strategy, so values will actually
# be cached inside blocks that utilize this strategy. See
# ActiveSupport::Cache::Strategy::LocalCache for more details.
class NullStore < Store
# Advertise cache versioning support.
def self.supports_cache_versioning?: () -> ::TrueClass
def clear: (?untyped? options) -> nil
def cleanup: (?untyped? options) -> nil
def increment: (untyped name, ?::Integer amount, ?untyped? options) -> nil
def decrement: (untyped name, ?::Integer amount, ?untyped? options) -> nil
def delete_matched: (untyped matcher, ?untyped? options) -> nil
private
def read_entry: (untyped key, **untyped options) -> nil
def write_entry: (untyped key, untyped entry, **untyped options) -> ::TrueClass
def delete_entry: (untyped key, **untyped options) -> ::FalseClass
end
end
end
module ActiveSupport
module Cache
module ConnectionPoolLike
def with: () { (untyped) -> untyped } -> untyped
end
# Redis cache store.
#
# Deployment note: Take care to use a *dedicated Redis cache* rather
# than pointing this at your existing Redis server. It won't cope well
# with mixed usage patterns and it won't expire cache entries by default.
#
# Redis cache server setup guide: https://redis.io/topics/lru-cache
#
# * Supports vanilla Redis, hiredis, and Redis::Distributed.
# * Supports Memcached-like sharding across Redises with Redis::Distributed.
# * Fault tolerant. If the Redis server is unavailable, no exceptions are
# raised. Cache fetches are all misses and writes are dropped.
# * Local cache. Hot in-memory primary cache within block/middleware scope.
# * +read_multi+ and +write_multi+ support for Redis mget/mset. Use Redis::Distributed
# 4.0.1+ for distributed mget support.
# * +delete_matched+ support for Redis KEYS globs.
class RedisCacheStore < Store
# Keys are truncated with their own SHA2 digest if they exceed 1kB
MAX_KEY_BYTESIZE: ::Integer
DEFAULT_REDIS_OPTIONS: ::Hash[untyped, untyped]
DEFAULT_ERROR_HANDLER: untyped
# The maximum number of entries to receive per SCAN call.
SCAN_BATCH_SIZE: ::Integer
# Advertise cache versioning support.
def self.supports_cache_versioning?: () -> ::TrueClass
module LocalCacheWithRaw
private
def write_entry: (untyped key, untyped entry, **untyped options) -> untyped
def write_multi_entries: (untyped entries, **untyped options) -> untyped
end
def self.build_redis: (?url: untyped? url, ?redis: untyped? redis, **untyped redis_options) -> untyped
private
def self.build_redis_distributed_client: (urls: untyped urls, **untyped redis_options) -> untyped
def self.build_redis_client: (url: untyped url, **untyped redis_options) -> untyped
public
attr_reader redis_options: untyped
attr_reader max_key_bytesize: untyped
# Creates a new Redis cache store.
#
# Handles four options: :redis block, :redis instance, single :url
# string, and multiple :url strings.
#
# Option Class Result
# :redis Proc -> options[:redis].call
# :redis Object -> options[:redis]
# :url String -> Redis.new(url: (trim non-ascii characters))
# :url Array -> Redis::Distributed.new([{ url: (trim non-ascii characters) }, { url: (trim non-ascii characters) }, (trim non-ascii characters)])
#
# No namespace is set by default. Provide one if the Redis cache
# server is shared with other apps: <tt>namespace: 'myapp-cache'</tt>.
#
# Compression is enabled by default with a 1kB threshold, so cached
# values larger than 1kB are automatically compressed. Disable by
# passing <tt>compress: false</tt> or change the threshold by passing
# <tt>compress_threshold: 4.kilobytes</tt>.
#
# No expiry is set on cache entries by default. Redis is expected to
# be configured with an eviction policy that automatically deletes
# least-recently or -frequently used keys when it reaches max memory.
# See https://redis.io/topics/lru-cache for cache server setup.
#
# Race condition TTL is not set by default. This can be used to avoid
# "thundering herd" cache writes when hot cache entries are expired.
# See <tt>ActiveSupport::Cache::Store#fetch</tt> for more.
def initialize: (?error_handler: untyped error_handler, ?race_condition_ttl: untyped? race_condition_ttl, ?expires_in: untyped? expires_in, ?compress_threshold: untyped compress_threshold, ?compress: bool compress, ?namespace: untyped? namespace, **untyped redis_options) -> untyped
def redis: () -> untyped
def inspect: () -> ::String
# Cache Store API implementation.
#
# Read multiple values at once. Returns a hash of requested keys ->
# fetched values.
def read_multi: (*untyped names) -> untyped
# Cache Store API implementation.
#
# Supports Redis KEYS glob patterns:
#
# h?llo matches hello, hallo and hxllo
# h*llo matches hllo and heeeello
# h[ae]llo matches hello and hallo, but not hillo
# h[^e]llo matches hallo, hbllo, ... but not hello
# h[a-b]llo matches hallo and hbllo
#
# Use \ to escape special characters if you want to match them verbatim.
#
# See https://redis.io/commands/KEYS for more.
#
# Failsafe: Raises errors.
def delete_matched: (untyped matcher, ?untyped? options) -> untyped
# Cache Store API implementation.
#
# Increment a cached value. This method uses the Redis incr atomic
# operator and can only be used on values written with the :raw option.
# Calling it on a value not stored with :raw will initialize that value
# to zero.
#
# Failsafe: Raises errors.
def increment: (untyped name, ?::Integer amount, ?untyped? options) -> untyped
# Cache Store API implementation.
#
# Decrement a cached value. This method uses the Redis decr atomic
# operator and can only be used on values written with the :raw option.
# Calling it on a value not stored with :raw will initialize that value
# to zero.
#
# Failsafe: Raises errors.
def decrement: (untyped name, ?::Integer amount, ?untyped? options) -> untyped
# Cache Store API implementation.
#
# Removes expired entries. Handled natively by Redis least-recently-/
# least-frequently-used expiry, so manual cleanup is not supported.
def cleanup: (?untyped? options) -> untyped
# Clear the entire cache on all Redis servers. Safe to use on
# shared servers if the cache is namespaced.
#
# Failsafe: Raises errors.
def clear: (?untyped? options) -> untyped
def mget_capable?: () -> untyped
def mset_capable?: () -> untyped
private
def set_redis_capabilities: () -> untyped
# Store provider interface:
# Read an entry from the cache.
def read_entry: (untyped key, **untyped options) -> untyped
def read_multi_entries: (untyped names, **untyped options) -> untyped
def read_multi_mget: (*untyped names) -> (::Hash[untyped, untyped] | untyped)
# Write an entry to the cache.
#
# Requires Redis 2.6.12+ for extended SET options.
def write_entry: (untyped key, untyped entry, ?race_condition_ttl: untyped? race_condition_ttl, ?expires_in: untyped? expires_in, ?raw: bool raw, ?unless_exist: bool unless_exist, **untyped options) -> untyped
def write_key_expiry: (untyped client, untyped key, untyped options) -> untyped
# Delete an entry from the cache.
def delete_entry: (untyped key, untyped options) -> untyped
# Nonstandard store provider API to write multiple values at once.
def write_multi_entries: (untyped entries, ?expires_in: untyped? expires_in, **untyped options) -> untyped
# Truncate keys that exceed 1kB.
def normalize_key: (untyped key, untyped options) -> untyped
def truncate_key: (untyped key) -> untyped
def deserialize_entry: (untyped serialized_entry, raw: untyped raw) -> untyped
def serialize_entry: (untyped entry, ?raw: bool raw) -> untyped
def serialize_entries: (untyped entries, ?raw: bool raw) -> untyped
def failsafe: (untyped method, ?returning: untyped? returning) { () -> untyped } -> untyped
def handle_exception: (returning: untyped returning, method: untyped method, exception: untyped exception) -> untyped
end
end
end
module ActiveSupport
module Cache
module Strategy
# Caches that implement LocalCache will be backed by an in-memory cache for the
# duration of a block. Repeated calls to the cache for the same key will hit the
# in-memory cache for faster access.
module LocalCache
# Simple memory backed cache. This cache is not thread safe and is intended only
# for serving as a temporary memory cache for a single thread.
class LocalStore < Store
def initialize: () -> untyped
def synchronize: () { () -> untyped } -> untyped
def clear: (?untyped? options) -> untyped
def read_entry: (untyped key, **untyped options) -> untyped
def read_multi_entries: (untyped keys, **untyped options) -> untyped
def write_entry: (untyped key, untyped value, **untyped options) -> ::TrueClass
def delete_entry: (untyped key, **untyped options) -> untyped
def fetch_entry: (untyped key, ?untyped? options) { () -> untyped } -> untyped
end
# Use a local cache for the duration of block.
def with_local_cache: () { () -> untyped } -> untyped
# Middleware class can be inserted as a Rack handler to be local cache for the
# duration of request.
def middleware: () -> untyped
def clear: (**untyped options) -> untyped
def cleanup: (**untyped options) -> untyped
def increment: (untyped name, ?::Integer amount, **untyped options) -> untyped
def decrement: (untyped name, ?::Integer amount, **untyped options) -> untyped
private
def read_entry: (untyped key, **untyped options) -> untyped
def read_multi_entries: (untyped keys, **untyped options) -> untyped
def write_entry: (untyped key, untyped entry, **untyped options) -> untyped
def delete_entry: (untyped key, **untyped options) -> untyped
def write_cache_value: (untyped name, untyped value, **untyped options) -> untyped
def local_cache_key: () -> untyped
def local_cache: () -> untyped
def bypass_local_cache: () { () -> untyped } -> untyped
def use_temporary_local_cache: (untyped temporary_cache) { () -> untyped } -> untyped
end
end
end
end
module ActiveSupport
module Cache
module Strategy
module LocalCache
class Middleware
# -
# This class wraps up local storage for middlewares. Only the middleware method should
# construct them.
# :nodoc:
attr_reader name: untyped
# -
# This class wraps up local storage for middlewares. Only the middleware method should
# construct them.
# :nodoc:
attr_reader local_cache_key: untyped
def initialize: (untyped name, untyped local_cache_key) -> untyped
def new: (untyped app) -> untyped
def call: (untyped env) -> untyped
end
end
end
end
end
module ActiveSupport
# See ActiveSupport::Cache::Store for documentation.
module Cache
# These options mean something to all cache implementations. Individual cache
# implementations may support additional options.
UNIVERSAL_OPTIONS: ::Array[untyped]
module Strategy
end
# Creates a new Store object according to the given options.
#
# If no arguments are passed to this method, then a new
# ActiveSupport::Cache::MemoryStore object will be returned.
#
# If you pass a Symbol as the first argument, then a corresponding cache
# store class under the ActiveSupport::Cache namespace will be created.
# For example:
#
# ActiveSupport::Cache.lookup_store(:memory_store)
# # => returns a new ActiveSupport::Cache::MemoryStore object
#
# ActiveSupport::Cache.lookup_store(:mem_cache_store)
# # => returns a new ActiveSupport::Cache::MemCacheStore object
#
# Any additional arguments will be passed to the corresponding cache store
# class's constructor:
#
# ActiveSupport::Cache.lookup_store(:file_store, '/tmp/cache')
# # => same as: ActiveSupport::Cache::FileStore.new('/tmp/cache')
#
# If the first argument is not a Symbol, then it will simply be returned:
#
# ActiveSupport::Cache.lookup_store(MyOwnCacheStore.new)
# # => returns MyOwnCacheStore.new
def self.lookup_store: (?untyped? store, *untyped parameters) -> untyped
# Expands out the +key+ argument into a key that can be used for the
# cache store. Optionally accepts a namespace, and all keys will be
# scoped within that namespace.
#
# If the +key+ argument provided is an array, or responds to +to_a+, then
# each of elements in the array will be turned into parameters/keys and
# concatenated into a single key. For example:
#
# ActiveSupport::Cache.expand_cache_key([:foo, :bar]) # => "foo/bar"
# ActiveSupport::Cache.expand_cache_key([:foo, :bar], "namespace") # => "namespace/foo/bar"
#
# The +key+ argument can also respond to +cache_key+ or +to_param+.
def self.expand_cache_key: (untyped key, ?untyped? namespace) -> untyped
private
def self.retrieve_cache_key: (untyped key) -> untyped
# Obtains the specified cache store class, given the name of the +store+.
# Raises an error when the store class cannot be found.
def self.retrieve_store_class: (untyped store) -> untyped
public
# An abstract cache store class. There are multiple cache store
# implementations, each having its own additional features. See the classes
# under the ActiveSupport::Cache module, e.g.
# ActiveSupport::Cache::MemCacheStore. MemCacheStore is currently the most
# popular cache store for large production websites.
#
# Some implementations may not support all methods beyond the basic cache
# methods of +fetch+, +write+, +read+, +exist?+, and +delete+.
#
# ActiveSupport::Cache::Store can store any serializable Ruby object.
#
# cache = ActiveSupport::Cache::MemoryStore.new
#
# cache.read('city') # => nil
# cache.write('city', "Duckburgh")
# cache.read('city') # => "Duckburgh"
#
# Keys are always translated into Strings and are case sensitive. When an
# object is specified as a key and has a +cache_key+ method defined, this
# method will be called to define the key. Otherwise, the +to_param+
# method will be called. Hashes and Arrays can also be used as keys. The
# elements will be delimited by slashes, and the elements within a Hash
# will be sorted by key so they are consistent.
#
# cache.read('city') == cache.read(:city) # => true
#
# Nil values can be cached.
#
# If your cache is on a shared infrastructure, you can define a namespace
# for your cache entries. If a namespace is defined, it will be prefixed on
# to every key. The namespace can be either a static value or a Proc. If it
# is a Proc, it will be invoked when each key is evaluated so that you can
# use application logic to invalidate keys.
#
# cache.namespace = -> { @last_mod_time } # Set the namespace to a variable
# @last_mod_time = Time.now # Invalidate the entire cache by changing namespace
#
# Cached data larger than 1kB are compressed by default. To turn off
# compression, pass <tt>compress: false</tt> to the initializer or to
# individual +fetch+ or +write+ method calls. The 1kB compression
# threshold is configurable with the <tt>:compress_threshold</tt> option,
# specified in bytes.
class Store
attr_reader silence: untyped
attr_reader options: untyped
alias silence? silence
private
def self.retrieve_pool_options: (untyped options) -> untyped
def self.ensure_connection_pool_added!: () -> untyped
public
# Creates a new cache. The options will be passed to any write method calls
# except for <tt>:namespace</tt> which can be used to set the global
# namespace for the cache.
def initialize: (?untyped? options) -> untyped
# Silences the logger.
def silence!: () -> untyped
# Silences the logger within a block.
def mute: () { () -> untyped } -> untyped
# Fetches data from the cache, using the given key. If there is data in
# the cache with the given key, then that data is returned.
#
# If there is no such data in the cache (a cache miss), then +nil+ will be
# returned. However, if a block has been passed, that block will be passed
# the key and executed in the event of a cache miss. The return value of the
# block will be written to the cache under the given cache key, and that
# return value will be returned.
#
# cache.write('today', 'Monday')
# cache.fetch('today') # => "Monday"
#
# cache.fetch('city') # => nil
# cache.fetch('city') do
# 'Duckburgh'
# end
# cache.fetch('city') # => "Duckburgh"
#
# You may also specify additional options via the +options+ argument.
# Setting <tt>force: true</tt> forces a cache "miss," meaning we treat
# the cache value as missing even if it's present. Passing a block is
# required when +force+ is true so this always results in a cache write.
#
# cache.write('today', 'Monday')
# cache.fetch('today', force: true) { 'Tuesday' } # => 'Tuesday'
# cache.fetch('today', force: true) # => ArgumentError
#
# The +:force+ option is useful when you're calling some other method to
# ask whether you should force a cache write. Otherwise, it's clearer to
# just call <tt>Cache#write</tt>.
#
# Setting <tt>skip_nil: true</tt> will not cache nil result:
#
# cache.fetch('foo') { nil }
# cache.fetch('bar', skip_nil: true) { nil }
# cache.exist?('foo') # => true
# cache.exist?('bar') # => false
#
#
# Setting <tt>compress: false</tt> disables compression of the cache entry.
#
# Setting <tt>:expires_in</tt> will set an expiration time on the cache.
# All caches support auto-expiring content after a specified number of
# seconds. This value can be specified as an option to the constructor
# (in which case all entries will be affected), or it can be supplied to
# the +fetch+ or +write+ method to effect just one entry.
#
# cache = ActiveSupport::Cache::MemoryStore.new(expires_in: 5.minutes)
# cache.write(key, value, expires_in: 1.minute) # Set a lower value for one entry
#
# Setting <tt>:version</tt> verifies the cache stored under <tt>name</tt>
# is of the same version. nil is returned on mismatches despite contents.
# This feature is used to support recyclable cache keys.
#
# Setting <tt>:race_condition_ttl</tt> is very useful in situations where
# a cache entry is used very frequently and is under heavy load. If a
# cache expires and due to heavy load several different processes will try
# to read data natively and then they all will try to write to cache. To
# avoid that case the first process to find an expired cache entry will
# bump the cache expiration time by the value set in <tt>:race_condition_ttl</tt>.
# Yes, this process is extending the time for a stale value by another few
# seconds. Because of extended life of the previous cache, other processes
# will continue to use slightly stale data for a just a bit longer. In the
# meantime that first process will go ahead and will write into cache the
# new value. After that all the processes will start getting the new value.
# The key is to keep <tt>:race_condition_ttl</tt> small.
#
# If the process regenerating the entry errors out, the entry will be
# regenerated after the specified number of seconds. Also note that the
# life of stale cache is extended only if it expired recently. Otherwise
# a new value is generated and <tt>:race_condition_ttl</tt> does not play
# any role.
#
# # Set all values to expire after one minute.
# cache = ActiveSupport::Cache::MemoryStore.new(expires_in: 1.minute)
#
# cache.write('foo', 'original value')
# val_1 = nil
# val_2 = nil
# sleep 60
#
# Thread.new do
# val_1 = cache.fetch('foo', race_condition_ttl: 10.seconds) do
# sleep 1
# 'new value 1'
# end
# end
#
# Thread.new do
# val_2 = cache.fetch('foo', race_condition_ttl: 10.seconds) do
# 'new value 2'
# end
# end
#
# cache.fetch('foo') # => "original value"
# sleep 10 # First thread extended the life of cache by another 10 seconds
# cache.fetch('foo') # => "new value 1"
# val_1 # => "new value 1"
# val_2 # => "original value"
#
# Other options will be handled by the specific cache store implementation.
# Internally, #fetch calls #read_entry, and calls #write_entry on a cache
# miss. +options+ will be passed to the #read and #write calls.
#
# For example, MemCacheStore's #write method supports the +:raw+
# option, which tells the memcached server to store all values as strings.
# We can use this option with #fetch too:
#
# cache = ActiveSupport::Cache::MemCacheStore.new
# cache.fetch("foo", force: true, raw: true) do
# :bar
# end
# cache.fetch('foo') # => "bar"
def fetch: (untyped name, ?untyped? options) { (untyped) -> untyped } -> untyped
# Reads data from the cache, using the given key. If there is data in
# the cache with the given key, then that data is returned. Otherwise,
# +nil+ is returned.
#
# Note, if data was written with the <tt>:expires_in</tt> or
# <tt>:version</tt> options, both of these conditions are applied before
# the data is returned.
#
# Options are passed to the underlying cache implementation.
def read: (untyped name, ?untyped? options) -> untyped
# Reads multiple values at once from the cache. Options can be passed
# in the last argument.