类:Mongo::CachingCursor
Overview
如果已经执行了相同的查询,则游标会先尝试从内存加载文档,然后再访问数据库。
实例属性摘要折叠
-
# cached_docs ⇒ 数组 <BSON::Document>
只读
private
游标的缓存文档。
从游标继承的属性
#connection 、 #context 、 #initial_result 、 #resume_token 、 # 服务器 、 #view
实例方法摘要折叠
-
#each (&block) ⇒ 对象
如果缓存的文档已存在于游标中,则我们将对其进行迭代,否则将照常进行。
-
#检查⇒ string
获取
Cursor的人类可读string表示形式。 -
# try_next ⇒ 对象
private
获取游标迭代的下一个文档,然后将该文档插入到 @cached_docs 数组中。
从Cursor继承的方法
#batch_size、#close、#lost?、#collection_name、finalize、#completely_iterated?、#get_more、#id、#initialize、#kill_spec、#refresh_timeout!
Retryable 中包含的方法
#read_worker、#select_server、#with_overload_retry、#write_worker
构造函数详情
该类从Mongo::Cursor继承了一个构造函数
实例属性详细信息
# cached_docs ⇒数组 <BSON::Document> (只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回游标的缓存文档。
25 26 27 |
# File 'lib/ Mongo/caching_cursor.rb', line 25 def cached_docs @cached_docs end |
实例方法详细信息
#each (&block) ⇒对象
如果缓存的文档已存在于游标中,则我们将对其进行迭代,否则将照常进行。
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ Mongo/caching_cursor.rb', line 34 def 每(和块) if @cached_docs @cached_docs.每(和块) 除非 已关闭? # 由 try_next 引发的 StopIteration 会结束此循环。 循环 do 文档 = try_next 产量 文档 if 文档 end end else 超 end end |
#检查⇒ string
获取 Cursor 的人类可读string表示形式。
56 57 58 |
# File 'lib/ Mongo/caching_cursor.rb', line 56 def 检查 " #<Mongo::CachingCursor:0 x # { object_id } @view= #{ @view .inspect } } > " end |
# try_next ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
获取游标迭代的下一个文档,然后将该文档插入到 @cached_docs 数组中。
64 65 66 67 68 69 70 |
# File 'lib/ Mongo/caching_cursor.rb', line 64 def try_next @cached_docs ||= [] 文档 = 超 @cached_docs << 文档 if 文档 文档 end |