Comments (5)
Hi! What’s some typical caching logic in an admin-area view where this is currently a problem?
from casein.
It’s going to vary based on the individual use case, but let’s say we have Author
objects and our casein/authors/_table.html.erb
view shows photo thumbnails as well as the count of the number of articles by that author. Looking up the photo and the article count takes some appreciable number of milliseconds when multiplied by 50 or 100 or however many authors we want to display in the table at one time.
In a perfect world, we could just cache the <tr>
for each author in casein/authors/_table.html.erb
like so:
<table class="table table-striped table-hover table-condensed">
<thead>...</thead>
<%= render partial: 'author', collection: authors, cached: true %>
</table>
Only the problem is, we are displaying the author’s created_at
and updated_at
dates in the user’s local time zone. So if someone from California is the first to populate the cache, then a visitor from New York is going to see these table rows showing created_at
times in PDT.
It was fairly easy for us at McSweeney’s to simply add local_time
to the Gemfile and replace the times with local_time
. Individual Casein users can of course do the same.
Totally up to you whether you want to make this part of Casein’s omakase defaults or not. If you wanted this to be supported out of the box, we could simply modify the template generators to use local_time
when creating Casein views of time attributes.
If that sounds helpful to you, happy to whip up a PR! And if not, happy to close this issue and simply go about our business manually tweaking the Casein-generated views in our own app, which is also not a problem!
from casein.
Thanks for the clear explanation of need. I hadn't considered that admin table views would benefit too much from global caching, mostly because of security implications. I totally see that, in many situations, users have the same security level and are viewing the same data, in the same way, and caching can help. But, I'm wondering if explicitly tailoring behavior for caching is a can of worms?
Other thoughts I'm having: Why is local time so special that it should get preferential treatment in the Casein core? (versus other user-specific presentation data in an otherwise shared view.) Does it make the basic code generators more complicated? (I guess not, if it's just a matter of using local_time
instead?) And, finally, what about backwards compatibly with users who have customized their generated template code? (I guess it would just work?)
I think most of my concerns are unfounded, right? If you think this is a minor tweak with only benefits, then yeah, let's go ahead and do it! Thanks again for bringing it up!
from casein.
You’re definitely right that going too far to anticipate or cater to specific caching use-cases is a can of worms: as you say, different users might have different permission levels, for one thing.
I don’t think it would make the generators any more complicated, and I don’t think there is a backwards-compatibility issue, but it does introduce a dependency. It’s a very small gem, but there’s a question of how well-maintained it will be going forward.
After thinking more about this, let’s keep it in the back of our minds, and in the meantime just let individual users customize as they need.
I’m going to close for now but I’m happy to revisit this!
from casein.
OK, that makes sense. But, yeah, happy to review if it becomes a more-general problem. Thanks again for documenting the issue!
from casein.
Related Issues (20)
- Rails 6 support? HOT 7
- casein 5.4.0 authlogic HOT 1
- Webpack Rails 5
- OmniAuth? HOT 1
- Override Casein templates HOT 1
- [calibration error] scrypt.rb:142:in `__sc_calibrate' HOT 1
- How can I generate admin users view HOT 3
- Rails 5? HOT 18
- Polymorphism HOT 1
- Using Bootsy WYSIWYG with Casein HOT 3
- how can I create an admin user in production env? HOT 1
- Possibility to use mongo db HOT 5
- Casein 5.2 - AdminUserSessions#new HOT 4
- has_many models within the form HOT 3
- Renaming the casein route HOT 1
- Redirecting to localhost HOT 5
- Glyphicons not working HOT 1
- Requirement of another ruby version HOT 2
- SQLite deprecation message when run rspec HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from casein.