I have been reading about caching and all the resources available out there, but I am just not sure if I need to use 3rd party add-ons like Memcachier in my app. Other than the front pages (Static Pages like Homepage, About, Contact Us, Terms, Privacy) all other pages require authentication and are all dynamically created. It's a small social networking app so the show page, index page, edit page are all dynamically created. The index action is constantly going to be updated.
我一直在阅读有关缓存和所有可用资源的信息,但我不确定是否需要在我的应用中使用像Memcachier这样的第三方加载项。除了首页(静态页面,如主页,关于,联系我们,条款,隐私),所有其他页面都需要身份验证,并且都是动态创建的。这是一个小型社交网络应用程序,因此显示页面,索引页面,编辑页面都是动态创建的。索引操作将不断更新。
I want to know if Rails will automatically cache my static pages and assets such as css, javascript, images? What kind of caching should I be using?
我想知道Rails是否会自动缓存我的静态页面和资产,如css,javascript,images?我应该使用什么样的缓存?
1 个解决方案
#1
3
If what you call static page are HTML files located in your public
folder, they are directly served by your web server (ex: Apache), and the request don't even go through Rails
如果您所谓的静态页面是位于公用文件夹中的HTML文件,则它们由您的Web服务器直接提供(例如:Apache),并且该请求甚至不通过Rails
If they are files located in your app/views
controller, the request goes through Rails, and it could be a good idea to implement page or fragment caching. Know that you can cache just parts of the pages, this is called fragment caching, and it's useful for dynamic pages that have static parts.
如果它们是位于app / views控制器中的文件,则请求通过Rails,并且实现页面或片段缓存可能是个好主意。知道你可以只缓存部分页面,这称为片段缓存,它对于具有静态部分的动态页面很有用。
Also, you can link a cache to a record, so first time the view related to this record is displayed, the cache is generated and used for the next requests. Then when you modify this record the cache is invalidated and the process start over.
此外,您可以将缓存链接到记录,因此首次显示与此记录相关的视图时,将生成缓存并将其用于下一个请求。然后,当您修改此记录时,缓存将失效,并且该过程将重新开始。
You don't need cache for your assets, they are compiles and not interpreted by Rails anymore in your production environment.
您不需要缓存资产,它们是编译的,而不再由生产环境中的Rails解释。
There is so many things about caching, and you can do a lot of good to your application with it (or a lot of bad is used incorrectly) and I cannot cover it all, let me give you some pointers that will teach you a lot:
有很多关于缓存的东西,你可以用你的应用程序做很多好事(或者很多错误使用不当)我无法覆盖它,让我给你一些指导,会教你很多:
http://railscasts.com/episodes/387-cache-digests
http://railscasts.com/episodes/169-dynamic-page-caching
http://railscasts.com/episodes/93-action-caching
#1
3
If what you call static page are HTML files located in your public
folder, they are directly served by your web server (ex: Apache), and the request don't even go through Rails
如果您所谓的静态页面是位于公用文件夹中的HTML文件,则它们由您的Web服务器直接提供(例如:Apache),并且该请求甚至不通过Rails
If they are files located in your app/views
controller, the request goes through Rails, and it could be a good idea to implement page or fragment caching. Know that you can cache just parts of the pages, this is called fragment caching, and it's useful for dynamic pages that have static parts.
如果它们是位于app / views控制器中的文件,则请求通过Rails,并且实现页面或片段缓存可能是个好主意。知道你可以只缓存部分页面,这称为片段缓存,它对于具有静态部分的动态页面很有用。
Also, you can link a cache to a record, so first time the view related to this record is displayed, the cache is generated and used for the next requests. Then when you modify this record the cache is invalidated and the process start over.
此外,您可以将缓存链接到记录,因此首次显示与此记录相关的视图时,将生成缓存并将其用于下一个请求。然后,当您修改此记录时,缓存将失效,并且该过程将重新开始。
You don't need cache for your assets, they are compiles and not interpreted by Rails anymore in your production environment.
您不需要缓存资产,它们是编译的,而不再由生产环境中的Rails解释。
There is so many things about caching, and you can do a lot of good to your application with it (or a lot of bad is used incorrectly) and I cannot cover it all, let me give you some pointers that will teach you a lot:
有很多关于缓存的东西,你可以用你的应用程序做很多好事(或者很多错误使用不当)我无法覆盖它,让我给你一些指导,会教你很多:
http://railscasts.com/episodes/387-cache-digests
http://railscasts.com/episodes/169-dynamic-page-caching
http://railscasts.com/episodes/93-action-caching