There is an expression "cache an object" when caching, but is this object an object-oriented object?

Asked 2 years ago, Updated 2 years ago, 38 views

I am studying cache by referring to the following articles.
I don't understand what "cache objects" means.

http://easyramble.com/rails-cache-fetch.html

For example, if you have a model called Text,
Does caching objects mean caching Text objects?

app/models/text.rb

class text
end

Also, I understand that fragment cache is a feature that caches some of the views available in rails.

Caching Objects and
I don't know how to use it differently when I use fragment cache.

At this point, we only have a vague image that makes it possible to cache objects in a wider range...

I look forward to your kind cooperation.

ruby-on-rails ruby

2022-09-30 18:46

1 Answers

Does caching objects mean caching Text objects?

Yes, the object in that case is considered synonymous with the instance.

text=Text.first
Rails.cache.write("some_cache_key", text)

However, if you write like this, you may misunderstand that "data retrieved from DB" or "instantiated objects" are cached.

In fact, it doesn't matter if it's a string, a number, or anything.
The basic idea of caching is to reuse previously used data to avoid time-consuming processing, and whatever data you want is fine.

Caching Objects and
I don't know how to use it differently when I use fragment cache.

fragment cache is a feature of rails that makes object caching convenient in views.

html generation is a time-consuming process, so I want to avoid it.
→ However, if you cache all the html, you can't handle pages that change part of it every time.
→ Then you can cache each part.But it's hard to write object cache every time.
→ Created a convenient mechanism for use
→ Let's call it fragment cache

It says (I think) around here.

Fragment caching is used for caching variable blocks without views without the entire action as a whole

Therefore, I think that the use of view is fragment cache, and the rest is object cache.
(Of course, you can use your own object cache, even if it's a view.)


2022-09-30 18:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.