diff options
author | Patrick Bajao <ebajao@gitlab.com> | 2019-06-05 07:59:48 +0300 |
---|---|---|
committer | Patrick Bajao <ebajao@gitlab.com> | 2019-06-05 08:19:59 +0300 |
commit | 2eecfd8f9d111c6518930b818a16daea8263b37f (patch) | |
tree | 12234d26e6e5a950ad69741e761ef7d3d079fdd1 /lib/gitlab/markdown_cache.rb | |
parent | b560ce1e666733f12c65e8b9f659c89256c1775b (diff) |
Use Redis for CacheMarkDownField on non AR models
This allows using `CacheMarkdownField` for models that are not backed
by ActiveRecord.
When the including class inherits `ActiveRecord::Base` we include
`Gitlab::MarkdownCache::ActiveRecord::Extension`. This will cause the
markdown fields to be rendered and the generated HTML stored in a
`<field>_html` attribute on the record. We also store the version
used for generating the markdown.
All other classes that include this model will include the
`Gitlab::MarkdownCache::Redis::Extension`. This add the `<field>_html`
attributes to that model and will generate the html in them. The
generated HTML will be cached in redis under the key
`markdown_cache:<class>:<id>`. The class this included in must
therefore respond to `id`.
Diffstat (limited to 'lib/gitlab/markdown_cache.rb')
-rw-r--r-- | lib/gitlab/markdown_cache.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/gitlab/markdown_cache.rb b/lib/gitlab/markdown_cache.rb new file mode 100644 index 00000000000..0354c710a3f --- /dev/null +++ b/lib/gitlab/markdown_cache.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Gitlab + module MarkdownCache + # Increment this number every time the renderer changes its output + CACHE_COMMONMARK_VERSION_START = 10 + CACHE_COMMONMARK_VERSION = 16 + + BaseError = Class.new(StandardError) + UnsupportedClassError = Class.new(BaseError) + end +end |