@REALTimothy0812
This is similar to the implementation I mentioned in the OP and the closest I’ve actually come to replication behaviour, but this isn’t particularly scalable nor the kind of similar/same replication I’m looking for. It’s not implicit, you have to force-replicate everything from remotes. I end up having to make an eagerly-loaded cache module to be able to support lazy-loaded modules and other scripts as well.
This isn’t always a smart solution. In the same way that you shouldn’t be saving data every time a change is made, there are cases where you should not be passing things every time a change is made either. Not even all properties for objects on Roblox replicate per change due to performance reasons. Keep in mind limitations for various API as well.
Worst case scenario, I’ll create a cache module and figure out how to go from there. That’s not quite solving my problem though because that isn’t replication and it’s easy to get lost once your project becomes large or you can’t keep track of everything.
-- Example
local Cache = {}
function Cache:NewItem(...)
-- ...
end
function Cache:RemoveItem(...)
-- ...
end
function Cache:SetReplicating(...)
-- ...
end
function Cache:GetDirectory(Name)
return self[Name] -- Or whatever
end
return setmetatable(Cache, NecessaryMT)
This may already be solving my problem or I may be overthinking it. Caching through a ModuleScript is certainly something I’ve considered (and attempted), but it’s neither similar or the same as the replication behaviour of ValueObjects. This is just standard handing off of data cross-environment, which I’m already capable of doing. I wouldn’t have created this post if that was what I was seeking.
@Halalaluyafail3
Already made note of that in the OP. Your implementation isn’t scalable for my use case because then I need to create cache behaviour for every ModuleScript. This also slightly hurts as far as readability goes. I could create a cache class or similar, but that’s basically what I explained above.
If that’s not what your code is meant to do, I apologise, though that’s how it comes off to me. I’m not particularly a fan of needing to ditch lazy-loading for a simple operation. Your client code also does the same thing - if a data change is made, it lazy-loads a module and directly mutates the target value. This can cause a problem if modules are loading where they shouldn’t be.
If at all possible, I’d like to stay free of caching behaviour unless that’s my only option. Selective replication is already fairly easy to do but I’m just unsure of what to do to mimic replication like in ValueObjects.
When the server makes changes to an object where properties replicate to the client, changes are instantaneous (or near-instantaneous, enough not to notice). Remotes still have a trip to make (in the case of RemoteFunctions to support change callbacks, a round trip) and are hindered by several factors. Remotes aren’t necessary to replicate in either scenario.