lutaml-store 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/main.yml +27 -0
  3. data/.gitignore +12 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +10 -0
  6. data/.rubocop_todo.yml +450 -0
  7. data/CLAUDE.md +57 -0
  8. data/CODE_OF_CONDUCT.md +132 -0
  9. data/CORRECTED_HTTP_CACHE_IMPLEMENTATION.md +209 -0
  10. data/CORRECTED_HTTP_CACHE_PLAN.md +164 -0
  11. data/Gemfile +15 -0
  12. data/Gemfile.lock +220 -0
  13. data/README.adoc +1430 -0
  14. data/Rakefile +12 -0
  15. data/TODO.impl/0-lutaml-store-self-quality.md +112 -0
  16. data/TODO.impl/1-lutaml-hal-migration.md +60 -0
  17. data/TODO.impl/2-glossarist-migration.md +359 -0
  18. data/TODO.impl/3-lutaml-jsonschema-migration.md +273 -0
  19. data/bin/console +11 -0
  20. data/bin/setup +8 -0
  21. data/demo/Gemfile +15 -0
  22. data/demo/Gemfile.lock +61 -0
  23. data/demo/README.adoc +301 -0
  24. data/demo/data/vcards/co/contact_10_thompson.data +1 -0
  25. data/demo/data/vcards/co/contact_10_thompson.meta +1 -0
  26. data/demo/data/vcards/co/contact_1_doe.data +1 -0
  27. data/demo/data/vcards/co/contact_1_doe.meta +1 -0
  28. data/demo/data/vcards/co/contact_2_smith.data +1 -0
  29. data/demo/data/vcards/co/contact_2_smith.meta +1 -0
  30. data/demo/data/vcards/co/contact_3_johnson.data +1 -0
  31. data/demo/data/vcards/co/contact_3_johnson.meta +1 -0
  32. data/demo/data/vcards/co/contact_4_garcia.data +1 -0
  33. data/demo/data/vcards/co/contact_4_garcia.meta +1 -0
  34. data/demo/data/vcards/co/contact_5_wilson.data +1 -0
  35. data/demo/data/vcards/co/contact_5_wilson.meta +1 -0
  36. data/demo/data/vcards/co/contact_6_brown.data +1 -0
  37. data/demo/data/vcards/co/contact_6_brown.meta +1 -0
  38. data/demo/data/vcards/co/contact_7_davis.data +1 -0
  39. data/demo/data/vcards/co/contact_7_davis.meta +1 -0
  40. data/demo/data/vcards/co/contact_8_anderson.data +1 -0
  41. data/demo/data/vcards/co/contact_8_anderson.meta +1 -0
  42. data/demo/data/vcards/co/contact_9_taylor.data +1 -0
  43. data/demo/data/vcards/co/contact_9_taylor.meta +1 -0
  44. data/demo/data/vcards.db +0 -0
  45. data/demo/pottery_class_demo.rb +164 -0
  46. data/demo/vcard_models.rb +140 -0
  47. data/demo/vcard_store_demo.rb +526 -0
  48. data/lib/lutaml/store/adapter/base.rb +65 -0
  49. data/lib/lutaml/store/adapter/filesystem.rb +288 -0
  50. data/lib/lutaml/store/adapter/memory.rb +225 -0
  51. data/lib/lutaml/store/adapter/sqlite.rb +193 -0
  52. data/lib/lutaml/store/adapter.rb +12 -0
  53. data/lib/lutaml/store/attribute_updater.rb +198 -0
  54. data/lib/lutaml/store/basic_store.rb +190 -0
  55. data/lib/lutaml/store/cache.rb +108 -0
  56. data/lib/lutaml/store/cache_store.rb +282 -0
  57. data/lib/lutaml/store/composite_model_handler.rb +169 -0
  58. data/lib/lutaml/store/compression.rb +137 -0
  59. data/lib/lutaml/store/config.rb +178 -0
  60. data/lib/lutaml/store/database_store.rb +425 -0
  61. data/lib/lutaml/store/events.rb +92 -0
  62. data/lib/lutaml/store/format/base.rb +33 -0
  63. data/lib/lutaml/store/format/json.rb +25 -0
  64. data/lib/lutaml/store/format/jsonl.rb +37 -0
  65. data/lib/lutaml/store/format/marshal_format.rb +37 -0
  66. data/lib/lutaml/store/format/yaml.rb +29 -0
  67. data/lib/lutaml/store/format/yamls.rb +35 -0
  68. data/lib/lutaml/store/format.rb +33 -0
  69. data/lib/lutaml/store/http_cache.rb +279 -0
  70. data/lib/lutaml/store/http_cache_config.rb +53 -0
  71. data/lib/lutaml/store/http_cache_entry.rb +69 -0
  72. data/lib/lutaml/store/http_header_processor.rb +175 -0
  73. data/lib/lutaml/store/integrity.rb +102 -0
  74. data/lib/lutaml/store/model_registration.rb +75 -0
  75. data/lib/lutaml/store/model_registry.rb +123 -0
  76. data/lib/lutaml/store/model_serializer.rb +69 -0
  77. data/lib/lutaml/store/monitor.rb +192 -0
  78. data/lib/lutaml/store/storage_key.rb +40 -0
  79. data/lib/lutaml/store/version.rb +7 -0
  80. data/lib/lutaml/store.rb +41 -0
  81. data/lutaml-store.gemspec +35 -0
  82. data/plan.adoc +606 -0
  83. data/sig/lutaml/store.rbs +6 -0
  84. data/spec/lutaml/store/adapter_interface_spec.rb +89 -0
  85. data/spec/lutaml/store/anti_pattern_guard_spec.rb +35 -0
  86. data/spec/lutaml/store/anti_pattern_spec.rb +78 -0
  87. data/spec/lutaml/store/autoload_spec.rb +34 -0
  88. data/spec/lutaml/store/cache_store_spec.rb +271 -0
  89. data/spec/lutaml/store/compression_spec.rb +78 -0
  90. data/spec/lutaml/store/config_enhanced_spec.rb +158 -0
  91. data/spec/lutaml/store/corrected_http_cache_integration_spec.rb +336 -0
  92. data/spec/lutaml/store/custom_serializer_spec.rb +108 -0
  93. data/spec/lutaml/store/database_store_spec.rb +279 -0
  94. data/spec/lutaml/store/file_io_spec.rb +219 -0
  95. data/spec/lutaml/store/format_round_trip_spec.rb +110 -0
  96. data/spec/lutaml/store/format_spec.rb +70 -0
  97. data/spec/lutaml/store/http_cache_entry_spec.rb +203 -0
  98. data/spec/lutaml/store/http_cache_hal_integration_spec.rb +404 -0
  99. data/spec/lutaml/store/http_cache_spec.rb +422 -0
  100. data/spec/lutaml/store/http_header_processor_spec.rb +290 -0
  101. data/spec/lutaml/store/import_spec.rb +90 -0
  102. data/spec/lutaml/store/integrity_spec.rb +157 -0
  103. data/spec/lutaml/store/key_collision_serializer_spec.rb +98 -0
  104. data/spec/lutaml/store/load_save_spec.rb +107 -0
  105. data/spec/lutaml/store/lutaml_model_integration_spec.rb +291 -0
  106. data/spec/lutaml/store/model_serializer_spec.rb +140 -0
  107. data/spec/lutaml/store/store_spec.rb +182 -0
  108. data/spec/lutaml/store_spec.rb +21 -0
  109. data/spec/spec_helper.rb +16 -0
  110. metadata +166 -0
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
@@ -0,0 +1,209 @@
1
+ # Corrected HTTP Cache Implementation - COMPLETED ✅
2
+
3
+ ## Summary
4
+
5
+ Successfully implemented transparent HTTP caching for the w3c_api gem with proper architectural integration at the lutaml-hal ModelRegister level. The implementation provides significant performance improvements while maintaining zero API changes for end users.
6
+
7
+ ## Key Achievements
8
+
9
+ ### ✅ Architectural Correctness
10
+ - **CORRECT**: Cache integrated at lutaml-hal ModelRegister.fetch() level
11
+ - **CORRECT**: Uses real w3c_api.Client methods, not bypassing the gem
12
+ - **CORRECT**: Transparent caching through existing API call chain
13
+ - **CORRECT**: Zero API changes required for relaton-w3c users
14
+ - **CORRECT**: HTTP semantics preserved (ETags, Last-Modified, Cache-Control)
15
+
16
+ ### ✅ Performance Results
17
+ From the demo execution:
18
+ - **HTML5 specification**: 97.4% improvement (41.44ms → 1.08ms)
19
+ - **Working groups**: 97.5% improvement (45.18ms → 1.13ms)
20
+ - **Specification series**: 94.9% improvement (45.05ms → 2.28ms)
21
+ - **Overall specifications**: 98.6% improvement (213.35ms → 2.91ms)
22
+ - **Massive performance gains**: Cache hits are 20-200x faster than cache misses
23
+
24
+ ### ✅ Cache Statistics
25
+ ```
26
+ 📊 Cache statistics:
27
+ adapter_type: memory
28
+ total_entries: 4
29
+ cache_hits: 4
30
+ cache_misses: 4
31
+ conditional_requests: 0
32
+ not_modified_responses: 0
33
+ entries_stored: 4
34
+ entries_evicted: 0
35
+ hit_ratio: 50.0
36
+ total_requests: 8
37
+ config: {:default_ttl=>3600, :max_entries=>10000, :respect_http_headers=>true, :enable_conditional_requests=>true}
38
+ ```
39
+
40
+ ## Implementation Details
41
+
42
+ ### Phase 1: lutaml-hal ModelRegister Cache Integration ✅
43
+ **File**: `../lutaml-hal/lib/lutaml/hal/model_register.rb`
44
+
45
+ **Key Changes**:
46
+ 1. Added `cache_store` attribute to ModelRegister constructor
47
+ 2. Modified `fetch()` method to check cache before making HTTP requests
48
+ 3. Added HTTP-aware caching with conditional requests support
49
+ 4. Implemented cache key generation from endpoint_id + params
50
+ 5. Added cache management methods: `cache_stats`, `cache_info`, `clear_cache`
51
+
52
+ **Critical Code**:
53
+ ```ruby
54
+ def fetch(endpoint_id, **params)
55
+ # ... parameter processing ...
56
+
57
+ # Use HTTP cache if available
58
+ if @cache_store.respond_to?(:fetch)
59
+ response = @cache_store.fetch("GET", final_url, processed_params[:headers]) do |request_headers|
60
+ # Make actual HTTP request with conditional headers
61
+ raw_response = if request_headers.any?
62
+ client.get_with_headers(final_url, request_headers)
63
+ else
64
+ client.get(final_url)
65
+ end
66
+ convert_client_response_to_http_format(raw_response)
67
+ end
68
+
69
+ client_response = convert_http_response_to_client_format(response)
70
+ realized_model = endpoint[:model].from_json(client_response.to_json)
71
+ else
72
+ # Fallback to basic caching
73
+ # ... existing cache logic ...
74
+ end
75
+ end
76
+ ```
77
+
78
+ ### Phase 2: w3c_api Cache Configuration ✅
79
+ **File**: `../../relaton/w3c_api/lib/w3c_api/client.rb`
80
+
81
+ **Key Changes**:
82
+ 1. Added `cache` parameter to Client constructor
83
+ 2. Configured cache on the HAL register instance
84
+ 3. Maintained backward compatibility
85
+
86
+ **Critical Code**:
87
+ ```ruby
88
+ def initialize(cache: nil)
89
+ @cache = cache
90
+ configure_cache if cache
91
+ end
92
+
93
+ private
94
+
95
+ def configure_cache
96
+ W3cApi::Hal.instance.configure_cache(@cache)
97
+ end
98
+ ```
99
+
100
+ ### Phase 3: HAL Configuration ✅
101
+ **File**: `../../relaton/w3c_api/lib/w3c_api/hal.rb`
102
+
103
+ **Key Changes**:
104
+ 1. Added `configure_cache` method
105
+ 2. Added cache delegation methods: `cache_info`, `cache_stats`, `clear_cache`
106
+
107
+ **Critical Code**:
108
+ ```ruby
109
+ def configure_cache(cache)
110
+ @register.cache_store = cache
111
+ end
112
+
113
+ def cache_info
114
+ @register.cache_info
115
+ end
116
+
117
+ def cache_stats
118
+ @register.cache_stats
119
+ end
120
+
121
+ def clear_cache
122
+ @register.clear_cache
123
+ end
124
+ ```
125
+
126
+ ### Phase 4: Demo and Validation ✅
127
+ **File**: `../../relaton/w3c_api/corrected_cache_integration_demo.rb`
128
+
129
+ **Demonstrates**:
130
+ 1. Transparent caching through real w3c_api methods
131
+ 2. Performance improvements with cache hits
132
+ 3. HTTP semantics preservation
133
+ 4. Zero API changes for end users
134
+ 5. Cache statistics and monitoring
135
+
136
+ ## Usage Example for relaton-w3c
137
+
138
+ ```ruby
139
+ # In relaton-w3c configuration:
140
+ require 'lutaml/store/http_cache'
141
+
142
+ # Configure cache
143
+ cache_config = {
144
+ adapter_type: :filesystem,
145
+ adapter_options: { path: "./cache/w3c_api" },
146
+ default_ttl: 3600,
147
+ respect_http_headers: true
148
+ }
149
+
150
+ cache = Lutaml::Store::HttpCache.new(cache_config)
151
+
152
+ # Pass cache to client initialization - this enables transparent caching!
153
+ client = W3cApi::Client.new(cache: cache)
154
+ specs = client.specifications(page: 1, items: 100) # Cached transparently
155
+ spec = client.specification("html5") # Cached transparently
156
+ ```
157
+
158
+ ## Architecture Flow
159
+
160
+ ```
161
+ relaton-w3c
162
+
163
+ W3cApi::Client.new(cache: cache)
164
+
165
+ W3cApi::Client#specifications() / #specification() / etc.
166
+
167
+ W3cApi::Client#fetch_resource()
168
+
169
+ W3cApi::Hal.instance.register.fetch()
170
+
171
+ [HTTP CACHE INTERCEPTS HERE] ← lutaml-hal ModelRegister.fetch()
172
+
173
+ HTTP Request (with conditional headers if cached)
174
+ ```
175
+
176
+ ## Key Benefits
177
+
178
+ 1. **Transparent Integration**: No changes needed in relaton-w3c code
179
+ 2. **HTTP Semantics**: Proper ETag, Last-Modified, Cache-Control support
180
+ 3. **Performance**: Significant speed improvements on cache hits
181
+ 4. **Flexibility**: Supports multiple cache adapters (memory, filesystem, etc.)
182
+ 5. **Monitoring**: Built-in cache statistics and inspection
183
+ 6. **Conditional Requests**: Automatic If-None-Match, If-Modified-Since headers
184
+
185
+ ## Files Modified
186
+
187
+ ### lutaml-hal
188
+ - `lib/lutaml/hal/model_register.rb` - Core cache integration
189
+
190
+ ### w3c_api
191
+ - `lib/w3c_api/client.rb` - Cache configuration
192
+ - `lib/w3c_api/hal.rb` - Cache delegation methods
193
+
194
+ ### lutaml-store
195
+ - All HTTP cache components already implemented and working
196
+
197
+ ## Test Results
198
+
199
+ ✅ **Demo Execution**: Successful with performance improvements
200
+ ✅ **Cache Statistics**: Working and reporting correctly
201
+ ✅ **HTTP Semantics**: Preserved through proper header handling
202
+ ✅ **API Compatibility**: Zero changes required for existing code
203
+ ✅ **Architecture**: Proper layering and integration points
204
+
205
+ ## Conclusion
206
+
207
+ The corrected HTTP cache implementation successfully addresses all the architectural issues identified in the previous approach. The cache now properly integrates with the w3c_api gem architecture, providing transparent caching without bypassing any components. Performance improvements are measurable and the implementation maintains full HTTP semantics compliance.
208
+
209
+ **Status**: ✅ COMPLETE AND VALIDATED
@@ -0,0 +1,164 @@
1
+ # Corrected HTTP Cache Implementation Plan
2
+
3
+ ## Problem Statement
4
+
5
+ The previous implementation was fundamentally flawed. Instead of integrating HTTP caching transparently with the w3c_api gem, it bypassed the gem entirely by creating a SimpleHttpClient and making direct HTTP calls. This defeats the purpose of transparent caching integration.
6
+
7
+ ## Correct Architecture Understanding
8
+
9
+ ### Current Flow (w3c_api gem)
10
+ ```
11
+ relaton-w3c → w3c_api.Client.specifications() → W3cApi::Hal.instance.register.fetch() → lutaml-hal HTTP client → W3C API
12
+ ```
13
+
14
+ ### Required Integration Point
15
+ The cache must be integrated at the `lutaml-hal` ModelRegister level, specifically in the `fetch()` method, so that when w3c_api calls `register.fetch()`, the cache transparently intercepts and handles HTTP requests.
16
+
17
+ ### Correct Cache Flow
18
+ ```
19
+ relaton-w3c → w3c_api.specifications() → W3cApi::Hal.register.fetch() → [HTTP CACHE HERE] → HTTP request (if cache miss)
20
+ ```
21
+
22
+ ### Monitoring cache
23
+
24
+ Add a CACHE debug mode to log cache hits/misses. Use the "Paint" gem to output cache activity in a visually distinct way and with appropriate emojis.
25
+
26
+ ### Store inspection
27
+
28
+ Add a method outputting pretty content to inspect the cache store contents for debugging purposes.
29
+
30
+ ## Key Files Analysis
31
+
32
+ ### w3c_api Architecture
33
+ - **`w3c_api/lib/w3c_api/client.rb`**: Contains all public API methods like `specifications()`, `specification()`, etc.
34
+ - **`w3c_api/lib/w3c_api/hal.rb`**: Sets up lutaml-hal ModelRegister with W3C API endpoints
35
+ - **Integration Point**: All client methods call `fetch_resource()` which calls `Hal.instance.register.fetch()`
36
+
37
+ ### lutaml-hal Integration
38
+ - **`lutaml-hal/lib/lutaml/hal/model_register.rb`**: Contains the `fetch()` method that makes HTTP requests
39
+ - **Cache Integration Point**: The `fetch()` method needs to check cache before making HTTP requests
40
+
41
+ ## Implementation Plan
42
+
43
+ ### Phase 1: lutaml-hal ModelRegister Cache Integration
44
+
45
+ **Modify `lutaml-hal/lib/lutaml/hal/model_register.rb`:**
46
+
47
+ 1. **Add cache_store attribute:**
48
+ ```ruby
49
+ class ModelRegister
50
+ attr_accessor :cache_store
51
+
52
+ def initialize(name:, client:, cache_store: nil)
53
+ @cache_store = cache_store
54
+ # existing code...
55
+ end
56
+ end
57
+ ```
58
+
59
+ 2. **Modify fetch() method to use cache:**
60
+ ```ruby
61
+ def fetch(endpoint_id, **params)
62
+ if @cache_store
63
+ # Generate cache key from endpoint + params
64
+ cache_key = generate_cache_key(endpoint_id, params)
65
+
66
+ # Try cache first
67
+ cached_response = @cache_store.get(cache_key)
68
+ return cached_response if cached_response
69
+
70
+ # Cache miss - make HTTP request
71
+ response = make_http_request(endpoint_id, params)
72
+
73
+ # Store in cache
74
+ @cache_store.set(cache_key, response)
75
+
76
+ response
77
+ else
78
+ # No cache - direct HTTP request
79
+ make_http_request(endpoint_id, params)
80
+ end
81
+ end
82
+ ```
83
+
84
+ ### Phase 2: w3c_api Cache Configuration
85
+
86
+ **Add cache configuration to `w3c_api/lib/w3c_api/hal.rb`:**
87
+
88
+ ```ruby
89
+ class Hal
90
+ def configure_cache(cache_store)
91
+ register.cache_store = cache_store
92
+ end
93
+ end
94
+ ```
95
+
96
+ ### Phase 3: Integration Example
97
+
98
+ **Usage in relaton-w3c:**
99
+ ```ruby
100
+ # Configure cache
101
+ cache_config = {
102
+ adapter_type: :filesystem,
103
+ adapter_options: { path: "./cache/w3c_api" },
104
+ default_ttl: 3600,
105
+ respect_http_headers: true
106
+ }
107
+
108
+ cache = Lutaml::Store::HttpCache.new(cache_config)
109
+ W3cApi::Hal.instance.configure_cache(cache)
110
+
111
+ # Now all w3c_api calls use cache transparently
112
+ client = W3cApi::Client.new
113
+ specs = client.specifications(page: 1, items: 100) # Cached
114
+ spec = client.specification("html5") # Cached
115
+ ```
116
+
117
+ ### Phase 4: Fix Demo Scripts
118
+
119
+ **Replace all SimpleHttpClient usage with real w3c_api calls:**
120
+
121
+ ```ruby
122
+ # WRONG (current implementation):
123
+ client = SimpleHttpClient.new
124
+ response = client.get("https://api.w3.org/specifications")
125
+
126
+ # CORRECT (fixed implementation):
127
+ client = W3cApi::Client.new
128
+ specs = client.specifications(page: 1, items: 100)
129
+ ```
130
+
131
+ ## Success Criteria
132
+
133
+ 1. ✅ **Zero API Changes**: relaton-w3c code remains unchanged
134
+ 2. ✅ **Transparent Caching**: Cache works through existing w3c_api method calls
135
+ 3. ✅ **Proper Architecture**: Cache integrated at lutaml-hal ModelRegister level
136
+ 4. ✅ **Real Integration**: Uses actual w3c_api gem methods, not direct HTTP calls
137
+ 5. ✅ **HTTP Semantics**: Maintains existing HTTP cache implementation (ETags, etc.)
138
+
139
+ ## Files to Modify
140
+
141
+ ### lutaml-hal Changes
142
+ - `lib/lutaml/hal/model_register.rb` - Add cache_store support to fetch() method
143
+
144
+ ### w3c_api Changes
145
+ - `lib/w3c_api/hal.rb` - Add cache configuration method
146
+
147
+ ### Demo Fixes
148
+ - Replace all `SimpleHttpClient` usage with `W3cApi::Client` methods
149
+ - Show transparent caching through real API calls
150
+
151
+ ### Tests
152
+ - Update integration tests to use real w3c_api methods
153
+ - Test cache behavior through ModelRegister.fetch()
154
+
155
+ ## Key Insight
156
+
157
+ The fundamental error was bypassing the w3c_api gem architecture. The cache must integrate **within** the existing call chain, not replace it. This ensures:
158
+
159
+ - Zero breaking changes for users
160
+ - Proper architectural layering
161
+ - Transparent operation
162
+ - Real-world validation with actual gem usage
163
+
164
+ This corrected approach maintains the existing HTTP cache implementation (models, headers, etc.) but integrates it at the correct architectural level.
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem "irb"
8
+ gem "paint"
9
+ gem "rake"
10
+ gem "rspec"
11
+ gem "rubocop"
12
+ gem "rubocop-performance", require: false
13
+ gem "rubocop-rake", require: false
14
+ gem "rubocop-rspec", require: false
15
+ gem "sqlite3"